Opened 12 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 |
Description
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.
Example:
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)
Change History (15)
Changed 12 years ago by
Attachment: | base.py.patch added |
---|
comment:1 Changed 12 years ago by
Hmm, we'll have to think hard about whether to add another attribute to HttpRequest
.
comment:2 Changed 12 years ago by
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 12 years ago by
Type: | → New feature |
---|
comment:4 Changed 12 years ago by
Severity: | → Normal |
---|
comment:5 Changed 12 years ago by
Needs documentation: | set |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Design 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 12 years ago by
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:9 Changed 11 years ago by
Summary: | Add "url_name" to HttpRequest → Save ResolverMatch in HttpRequest |
---|
comment:11 Changed 11 years ago by
Cc: | real.human@… added |
---|
comment:12 Changed 11 years ago by
Discussion on django-developers: https://groups.google.com/d/topic/django-developers/EJxfOSZOMR4/discussion
comment:14 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch of "django/core/handlers/base.py"