DjangoDjango

Serve static and media files by Django while in Debug mode

Feb 12, 2014 · Updated: Jul 12, 2021 · by Tim Kamanin

Media and static files won't be served in devel mode untill you put this at the end of the main urls.py file:

if settings.DEBUG:
    urlpatterns += patterns(
        "",
        (
            r"^media/(?P.*)$",
            "django.views.static.serve",
            {"document_root": settings.MEDIA_ROOT},
        ),
        (
            r"^static/(?P.*)$",
            "django.views.static.serve",
            {"document_root": settings.STATIC_ROOT},
        ),
    )

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓