Ram Rachum Ram Rachum - 1 year ago 92
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download