Comments on: Django static media always returning 404 not found Code and comments on web development, Django, Python and things (un)related. Wed, 03 Apr 2013 13:15:20 +0000 hourly 1 By: Glyn Mooney Thu, 14 Apr 2011 09:07:33 +0000 You are a star! Thanks mate :)

By: morgan Mon, 14 Feb 2011 00:45:02 +0000 wow very helpful, I hadn’t changed me admin-media url and was comparing my settings file between two django apps trying to figure out why the static server was returning 404. By default a django settings project should set them differently to avoid this problem.

By: David Talbot Sun, 21 Nov 2010 10:00:50 +0000 I’ve been struggling with *exactly* the same problem. Thanks for posting!

By: Ingmar Fri, 08 Oct 2010 16:03:24 +0000 The term “media” always struck me as a poor choice, as it means both everything and nothing and is guaranteed to confuse a Django newcomer (as it once did confuse me). Which is why my Django deployments are set up with what I consider less confusing terminology:

/upload – the stuff that users uploaded to the server, i.e. what Django refers to as media (served under MEDIA_URL and stored in MEDIA_ROOT on the filesystem).
/static – the static part of my project/site, such as icons, Javascript files, CSS, etc. (I keep this well separate from /upload, as it is truly static and lives in version control, unlike /upload)
/adminmedia – the static parts of Django’s admin interface, which is served under ADMIN_MEDIA_PREFIX and part of Django. Arguably this should live under /static/admin, but I prefer the clean separation in case I need to more one or the other to a separate host for whatever reason (performance, CDN, …)

Hopefully if Django ever decides to make some rather backwards-incompatible changes, this gets cleaned up :-)

By: Scott Thu, 07 Oct 2010 08:15:42 +0000 Ah, if I’d read the docs I might have seen this warning:

“Be careful not to use the same path as your ADMIN_MEDIA_PREFIX (which defaults to /media/) as this will overwrite your URLconf entry.”

By: Brent Tubbs Thu, 07 Oct 2010 02:29:06 +0000 It’s not your fault. By default, Django puts the following in for a new site:

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: “”, “”

# URL prefix for admin media — CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: “”, “/media/”.

One of my biggest Django peeves is the built-in confusion over the right way to serve static media and refer to it in templates. The default source code above strongly implies doing it one (confusing) way, while the docs ( suggest something completely different (setting up a STATIC_DOC_ROOT variable).