Hi everyone,
I am having trouble displaying images stored on my laptop using Django
templates.To highlight the problem I am using a view called test which
renders a template called test.html. code for them is as follows:
def test(request):
return
render_to_response('test.html',context_instance=RequestContext(request,processors=[custom_proc]))
def custom_proc(request):
return {'MEDIA_URL':settings.MEDIA_URL}
"test.html"
<html>
<head> this is a test page </head>
<body>
<img src="{{MEDIA_URL}}photos/hilton1.jpg" alt="Paris Hilton" />
</body>
</html>
on rendering this page, the image does not get displayed instead
displaying the text associated with "alt" in the img tag.On viewing
page source,it shows src="/multimedia/photos/hilton1.jpg" which is the
correct location of the image file.
My settings are as follows:
MEDIA_ROOT =
os.path.join(os.path.abspath(os.path.dirname(__file__)),'multimedia')
MEDIA_URL = '/multimedia/'
ADMIN_MEDIA_PREFIX = '/media/'
finally here are the settings in "urls.py"
if settings.DEBUG:
from django.views.static import serve
if settings.MEDIA_URL.startswith('/'):
_media_url=settings.MEDIA_URL[1:]
urlpatterns+=patterns('',(r'^%s(?P<path>.*)$' % _media_url,serve,
{'document_root':settings.MEDIA_ROOT,}))
del(_media_url,serve)
I have tried searching the net without any resolution to this
problem.Any help would be greatly appreciated.
Thanks
Abhas
--
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.