I'm trying to allow serving files from my media directory, but the media url isn't getting included... here's my code:
from django.conf.urls.static import static
urlpatterns = [ ... ]
if settings.LOCALHOST_DEVELOPMENT:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
From a Django shell session:
>>> from django.conf import settings
>>> settings.LOCALHOST_DEVELOPMENT
True
>>> settings.MEDIA_URL
'/media/'
>>> settings.MEDIA_ROOT
'/Users/[my username]/code/survey_server/media'
>>> from survey_server import urls
That last call return a list of urls without media url...
>>> from django.conf.urls.static import static
>>> static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
[]
... and it looks like the media url wasn't included because that static call is returning an empty list. Why is this empty?
Setting DEBUG = True
in my settings.py file got this working.
Here's what the documentation for this function says (emphasis added):
Helper function to return a URL pattern for serving files in debug mode