django - RequestContext returns 404 error for my imagaes? -
i stumbled on silly situation django's requestcontext thing. here question:
i stored images in media/uploads file. in template i'm using :
{% photo in photos %} <a href="#"> <img src="{{gallery_root}}/{{photo.get_name}}" /></a> {% endfor %}
my view :
def gallery_view(request): photos = photo.objects.all() return render_to_response('gallery/samplegallery.html',{'photos':photos},context_instance=requestcontext(request))
in settings file :
gallery_root = os.path.join(media_root, "media/uploads")
and have contextprocessor file contains:
from django.conf import settings def gallery_root(request): return {'gallery_root':settings.gallery_root}
when open template, image's path appears server gives 404, path seems correct django can not serves them.. what's reason can not see images on template ?
the image source appears :
<a href="#"> <img src="/users/imperium/desktop/sample/media/uploads/popo.jpg" /></a>
hey there, it's media isn't being served propery. try in urls.py file.
# if we're in debug mode, allow django serve media # considered inefficient , isn't secure. django.conf import settings if settings.debug: urlpatterns += patterns('', (r'^media/(?p<path>.*)$', 'django.views.static.serve', {'document_root': settings.gallery_root}), )
Comments
Post a Comment