Comments on: Django static media always returning 404 not found http://scottbarnham.com/blog/2010/10/06/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 http://wordpress.org/?v=4.3 By: Glyn Mooney http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-1017 Thu, 14 Apr 2011 09:07:33 +0000 http://scottbarnham.com/blog/?p=74#comment-1017 You are a star! Thanks mate :)

]]>
By: morgan http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-998 Mon, 14 Feb 2011 00:45:02 +0000 http://scottbarnham.com/blog/?p=74#comment-998 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 http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-884 Sun, 21 Nov 2010 10:00:50 +0000 http://scottbarnham.com/blog/?p=74#comment-884 I’ve been struggling with *exactly* the same problem. Thanks for posting!

]]>
By: Ingmar http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-859 Fri, 08 Oct 2010 16:03:24 +0000 http://scottbarnham.com/blog/?p=74#comment-859 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 http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-858 Thu, 07 Oct 2010 08:15:42 +0000 http://scottbarnham.com/blog/?p=74#comment-858 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 http://scottbarnham.com/blog/2010/10/06/django-static-media-always-returning-404-not-found/comment-page-1/#comment-853 Thu, 07 Oct 2010 02:29:06 +0000 http://scottbarnham.com/blog/?p=74#comment-853 It’s not your fault. By default, Django puts the following in settings.py 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: “http://media.lawrence.com”, “http://example.com/media/”
MEDIA_URL = ”

# URL prefix for admin media — CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: “http://foo.com/media/”, “/media/”.
ADMIN_MEDIA_PREFIX = ‘/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 (http://docs.djangoproject.com/en/dev/howto/static-files/) suggest something completely different (setting up a STATIC_DOC_ROOT variable).

]]>