On Mon, Oct 25, 2010 at 4:04 PM, d <[email protected]> wrote:
> I have been searching for solutions whole day.
> How would I display image file in django template. I have already set
> MEDIA_ROOT and MEDIA_URL.
>
You mean image as in static image or from Image model?
If static image, then this is the process:
- lets say image is in ProjectNameFolder/static/images/img1.jpeg
- Have this in your settings.py
import os.path
BASE_PATH = os.path.dirname(__file__)
SITE_ROOT = BASE_PATH
STATIC_DOC_ROOT = BASE_PATH+'/static'
- In your urls.py:
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
)
- in your template <img src="/static/images/img1.jpeg"/>
This should work. Note that this serves the static content from the django
dev server and should be used purely in your dev env.
-V-
http://twitter.com/venkasub
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.