Why is django not serving my media files? -


in settings.py,

root_path = os.path.dirname(__file__) #staticfiles_dirs = static_root = os.path.join(root_path, 'static') media_root = os.path.join(root_path, 'media') static_url = '/static/' media_url = '/media/ 

in template,

     <div class=" event_image">       <img src="{{ media_url }}{{ restaurant.logo }}" />       </div> 

this doesnot work in development, returns 404 "get /media/restaurant_detail/restaurant_detail/information_about_object.jpg http/1.1" 404 178672

what doing wrong,what right way go works in both in dev't , production. looked here (django 1.4 serving media_url , static_url files on development server) in vain.

turns out had include urls,my urls

urlpatterns += patterns('',     url(r'^static/(?p<path>.*)$', 'django.views.static.serve', {'document_root': settings.static_root}),     url(r'^media/(?p<path>.*)$', 'django.views.static.serve', {'document_root': settings.media_root}),  ) 

the above worked..

my project structure -myproject -- media -- static -- templates -- settings.py -- manage.py -- app 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -