#7879 closed (wontfix)
reverse/url tag assumes view is a module-level callable
Reported by: | miracle2k | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
django.core.urlresolvers.reverse, when called with a string argument, requires that string to reference a view inside a module, which means that the following won't work, since site is a class, and admin is the module.
reverse('django.contrib.admin.site.root')
The faulty code is get_callable inside urlresolvers.py.
Change History (4)
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|
comment:3 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This is really fiddly to handle all the cases, since it requires stepping through one dotted piece at a time checking if it's something to import or a class or whatever. Since reverse-resolving is already slow to start up as it is, it's not really worth it.
The correct thing to do here is to use the named URL-pattern form:
url(r'^admin/(.*)', admin.sites.root, name='my-admin-root'),
and then {% url my-admin-root "" %}
will do work as you expect.
It's arguably a bug that the empty string is needed if you only want the root, but that's an issue with reverse()
and I've opened #9239 for that.
Reversing stuff in
AdminSite
is a much larger problem that needs to be dealt with later on.