Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#10636 closed (fixed)

Development server fails if settings module does not define ADMIN_MEDIA_PREFIX

Reported by: Lee Phillips <lee@…> Owned by: jezdez
Component: django-admin.py runserver Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

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.

Change History (11)

comment:1 follow-up: Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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?

comment:2 in reply to: ↑ 1 Changed 6 years ago by Lee Phillips <lee@…>

  • Resolution set to invalid
  • Status changed from new to closed

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?

comment:3 Changed 6 years ago by tvon

  • Resolution invalid deleted
  • Status changed from closed to reopened

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.

comment:4 Changed 6 years ago by Alex

  • Resolution set to invalid
  • Status changed from reopened to closed

I agree with Karen, this is doing exactly what it says, any request that begins with that is routed to admin media handling.

comment:5 Changed 5 years ago by dmlodecki@…

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Version changed from 1.0 to 1.2

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.

comment:6 Changed 5 years ago by dmlodecki@…

For further clarity: It is not that the Admin media don't serve with a 404... It is that the entire project goes 404, even non-admin pages.

comment:7 Changed 5 years ago by jezdez

  • Owner changed from nobody to jezdez
  • Status changed from reopened to new

comment:8 Changed 5 years ago by rasca

  • Component changed from Uncategorized to django-admin.py runserver
  • milestone set to 1.3
  • Needs documentation set
  • Needs tests set
  • Owner changed from jezdez to rasca
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.2 to SVN

comment:9 Changed 5 years ago by rasca

  • Owner changed from rasca to jezdez
  • Status changed from assigned to new

comment:10 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(In [14593]) Fixed #10636 -- Added check to make sure the ADMIN_MEDIA_PREFIX setting is properly set before serving files with the AdminMediaHandler.

comment:11 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top