djangodjango-staticfilesdjango-dev-server

Serving static files in development with django-devserver


I finally got around to trying out django-devserver. It's installed and working but static files refuse to load (Django 1.3). (Note: static files work fine with the standard runserver management command, before switching to django-devserver, so all the configuration settings are fine.) I came across this bit in the README:

DEVSERVER_IGNORED_PREFIXES = ['/media', '/uploads']

A list of prefixes to surpress and skip process on. By default, ADMIN_MEDIA_PREFIX, MEDIA_URL and STATIC_URL (for Django >= 1.3) will be ignored (assuming MEDIA_URL and STATIC_URL is relative)

Which seems very odd because the whole point of using runserver is to not have to have an actual real web server setup, especially just to serve static files in development.

Oddly, though, even though it mentions ADMIN_MEDIA_PREFIX, I found that the admin actually loads all its static resources fine, which leads me to believe that maybe I'm just missing something somewhere.

Anyone ideas?


Solution

  • From the URL in @MarkLavin's comment, I actually came across (rather, reminded of) the following:

    # Add to end of urls.py
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()
    

    That will allow the static files to be served and is ignored in production, so there doesn't seem to be any side effects to the approach. However, it irks me a little to have to modify my urls.py just for this, but it's probably only temporary until the noted pull request is merged.

    If anyone has any other solutions, feel free to add them, though.