Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7879 closed (wontfix)

reverse/url tag assumes view is a module-level callable

Reported by: miracle2k Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 Changed 8 years ago by Eric Holscher

milestone: 1.0
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 8 years ago by James Bennett

milestone: 1.0post-1.0

Reversing stuff in AdminSite is a much larger problem that needs to be dealt with later on.

comment:3 Changed 8 years ago by Malcolm Tredinnick

Resolution: wontfix
Status: newclosed

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.

comment:4 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

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