Opened 14 years ago
Closed 12 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)
by , 14 years ago
Attachment: | base.py.patch added |
---|
comment:1 by , 14 years ago
Hmm, we'll have to think hard about whether to add another attribute to HttpRequest
.
comment:2 by , 14 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 , 14 years ago
Type: | → New feature |
---|
comment:4 by , 14 years ago
Severity: | → Normal |
---|
comment:5 by , 14 years ago
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 by , 14 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:9 by , 12 years ago
Summary: | Add "url_name" to HttpRequest → Save ResolverMatch in HttpRequest |
---|
comment:11 by , 12 years ago
Cc: | added |
---|
comment:12 by , 12 years ago
Discussion on django-developers: https://groups.google.com/d/topic/django-developers/EJxfOSZOMR4/discussion
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch of "django/core/handlers/base.py"