Opened 13 years ago

Closed 11 years ago

#15695 closed New feature (fixed)

Save ResolverMatch in HttpRequest

Reported by: nischu7 Owned by: nobody
Component: Core (Other) Version: 1.3
Severity: Normal Keywords:
Cc: real.human@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


In order to simplify the implementation of navigation systems within templates, the HttpRequest instance passed around in the request cycle should held a "url_name" property.

You define a url that looks like this one:

url(r'^$', 'core.views.dashboard', name='dashboard'),

You'll be able to get the name by accessing "request.url_name". This is more efficient than having to re-resolve the URL in the views/middleware classes/template tag implementations etc.

Attachments (1) (1.1 KB ) - added by nischu7 13 years ago.
patch of "django/core/handlers/"

Download all attachments as: .zip

Change History (15)

by nischu7, 13 years ago

Attachment: added

patch of "django/core/handlers/"

comment:1 by Adrian Holovaty, 13 years ago

Hmm, we'll have to think hard about whether to add another attribute to HttpRequest.

comment:2 by nischu7, 13 years ago

I appreciate your sceptical attitude in favor of Django's quality.
On the other hand, storing the "url_name" or even better, the whole ResolverMatch object returned by "RegexURLResolver.resolve" would make things more efficient since you won't need to re-resolve the URL in later phases.

comment:3 by Luke Plant, 13 years ago

Type: New feature

comment:4 by Luke Plant, 13 years ago

Severity: Normal

comment:5 by Julien Phalip, 13 years ago

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedDesign decision needed

I'm a bit concerned about this as url_name would only be one part of the picture -- for this feature to be really useful and versatile you'd also need to pass along the url resolving parameters (args and kwargs), but then that would be even more stuff to cram into the HttpRequest object.

This is still an interesting idea though, so I'll mark as DDN in case another clean implementation can be suggested.

comment:6 by nischu7, 13 years ago

As I already stated in the 2nd comment, I'd just store the ResolverMatch object as it is since it contains everything we need (view callback function, args, kwargs, the url name, as well as the app name). Should I submit another patch?

comment:7 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 by Aymeric Augustin, 11 years ago

Summary: Add "url_name" to HttpRequestSave ResolverMatch in HttpRequest

comment:10 by Aymeric Augustin, 11 years ago

#16087 is related.

comment:11 by Tai Lee, 11 years ago

Cc: real.human@… added

comment:14 by Florian Apolloner <florian@…>, 11 years ago

Resolution: fixed
Status: newclosed

In b946db5241b924c72c1079ce30d9b368e2b82f07:

Fixed #15695 -- Added ResolverMatch to the request object.

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