Opened 8 years ago

Closed 7 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 8 years ago.
patch of "django/core/handlers/"

Download all attachments as: .zip

Change History (15)

Changed 8 years ago by nischu7

Attachment: added

patch of "django/core/handlers/"

comment:1 Changed 8 years ago by Adrian Holovaty

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

comment:2 Changed 8 years ago by nischu7

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 Changed 8 years ago by Luke Plant

Type: New feature

comment:4 Changed 8 years ago by Luke Plant

Severity: Normal

comment:5 Changed 8 years ago by Julien Phalip

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

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 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 Changed 7 years ago by Aymeric Augustin

Summary: Add "url_name" to HttpRequestSave ResolverMatch in HttpRequest

comment:10 Changed 7 years ago by Aymeric Augustin

#16087 is related.

comment:11 Changed 7 years ago by Tai Lee

Cc: real.human@… added

comment:14 Changed 7 years ago by Florian Apolloner <florian@…>

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