Description

I defined ADMIN_MEDIA_PREFIX = "" in my settings module and found that this caused the development server to not work: all requests for URLs returned a "URL not found", and the server did not log the requests to stdout as it normally does. Setting ADMIN_MEDIA_PREFIX to any nonempty string fixes this.

Oldest firstNewest firstThreaded

Show commentsShow property changes

Change History (11)

So don't do that? The development server has a built-in admin media server that keys off of ADMIN_MEDIA_PREFIX -- any url that beings with ADMIN_MEDIA_PREFIX is routed to the built-in server that serves the files in the admin media directory. So if you set ADMIN_MEDIA_PREFIX to "", I'd guess everything gets routed to the built-in media server, which of course isn't going to work. It probably won't even be able to server the admin media files since the setting is expected (as noted in the comment for it in settings.py) to include a trailing slash, and you left even that out. It isn't clear what you expect to happen instead?

Replying to kmtracey:
OK, your explanation is good, so I've changed my ticket to "invalid" (I hope that's the right thing). My naive expectation was that, since I didn't have any admin media, that it was better to not define a place for the server to look for it, but, as you've explained, the side-effect was that all URLs were interpreted requests for admin media. Maybe a little extra documentation would be in order?

I don't see why this is invalid. If the server requires that ADMIN_MEDIA_PREFIX be non-empty, then that should be checked and an error should be reported. If an exception was thrown that would be fine, but currently there is zero indication of what the actual problem is.

From kmtracey in #14607:It is a duplicate: #10636 is the same. Why did you want to set ADMIN_MEDIA_PREFIX to an empty value? Perhaps the docs could warn to not do that, or some check could be put in to raise ImproperlyConfigured if that is done, by I'm a little mystified as to why people are doing this. If you really want to pursue getting something changed here, please reopen #10636 and provide a concrete suggestion for how to improve matters (and please try the current trunk behavior, since it may have changed recently given the static file changes).

Leaving ADMIN_MEDIA_PREFIX is certainly an incorrect configuration, but one that people may try when attempting to serve admin media files. People are doing it accidentally, not deliberately. The problem is that despite DEBUG being set to true, no helpful trace is provided, just the simple 404.

Because it manifests in the user's browser as a standard 404, this failure mode makes some people think there might be a problem with their django or webserver setup, rather than a problem with their code. It appears like the web browser is unable to reach the webserver.

Concrete suggestion for improvement: If ADMIN_MEDIA_PREFIX is empty, output an error trace page saying "ADMIN_MEDIA_PREFIX in settings.py is empty. This is probably not what you want to do." Additionally, the docs should warn against this configuration.