Using Django to Serve Static Files in Development
by David Orkin on Oct.06, 2009,under Python, Django
So by default Django doesnt serve static files because, well, it doesn't serve them as well as a web server like Apache would. But one small thing struck me as odd in the online documentation that describes how to serve static files in the snippet below
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': '/path/to/media'}),
)
Why wouldn't you use the MEDIA_ROOT variable from settings.py? Granted this may not be the biggest issue, but if given the choice, I think my preference would be to keep the settings for the application in settings.py, you know the file for application settings. Yes I know this shouldn't be used outside of development, but still wonder what the advantage of doing it this way would be...
Below is the code I am currently using,
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)