Ram Rachum Ram Rachum - 5 months ago 18
Python Question

Serving static media during Django development: Why not MEDIA_ROOT?

I read this guide about serving static media with Django during development.

I noticed that

were not used in this. Why? What's the difference?

I tried doing it with
, and got weird results.


In a production situation you will want your media to be served from your front end web server (Apache, Nginx or the like) to avoid extra load on the Django/Python process. The MEDIA_URL and MEDIA_ROOT are usually used for this.

Running the built in Development server you will need to set the correct url in your url.py file - I normally use something like this:

from django.conf import settings

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

Which picks up the MEDIA_ROOT from your settings file meaning that it works for development and live.