Opened 7 years ago
Closed 6 years ago
#28766 closed New feature (fixed)
Add route information to ResolverMatch
Reported by: | Benjamin Wohlwend | Owned by: | Melvyn Sopacua |
---|---|---|---|
Component: | Core (URLs) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The new route-based URL patterns are fantastic, but when introspecting the ResolverMatch object, the route information is not available. The route would be of great use for tools/libraries that need to introspect the URL resolver.
GitHub PR with a first try at adding this will follow.
Change History (13)
comment:1 by , 7 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Thanks for the patch. If it's ready to review you can deassign the Trac ticket. :)
follow-up: 4 comment:3 by , 7 years ago
For URL patterns that use re_path()
is the route already available from ResolverMatch
? If not, I'm unsure why this attribute would only be set for path()
.
(By the way, there's no need to deassign the ticket to get it in the review queue.)
comment:4 by , 7 years ago
Replying to Tim Graham:
For URL patterns that use
re_path()
is the route already available fromResolverMatch
? If not, I'm unsure why this attribute would only be set forpath()
.
re_path()
uses RegexPattern
, which doesn't have a route, but a regex. Do you think the regex should be set in that case? That would simplify the code a bit. Instead of getattr(pattern._route)
, we could just use str(pattern)
(__str__
prints _route
for RoutePattern
objects, and _regex
for RegexPattern
).
comment:6 by , 7 years ago
OK. However, in that case I think the attribute on ResolverMatch
should be named differently, since AFAICT, "route" is specific to the new simplified URLs from DEP 201. Maybe ResolverMatch.pattern
?
comment:7 by , 7 years ago
The first argument of re_path()
is also documented as route
so I think it's okay to use that.
comment:8 by , 7 years ago
Patch needs improvement: | set |
---|
comment:9 by , 6 years ago
Has patch: | unset |
---|---|
Owner: | changed from | to
Patch needs improvement: | unset |
Version: | 2.0 → master |
Working on patch + test + docs.
@tim Do I need to submit a new document for contribution or can you link the one I submitted already to this [github account](https://github.com/mes3yd/)? The old account will get closed as soon as there's nothing pending on it anymore.
comment:10 by , 6 years ago
You don't need to submit another Contributor License Agreement. Those agreements are linked to you, not to your GitHub account.
comment:11 by , 6 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
PR with comments for improvement.
comment:12 by , 6 years ago
Patch needs improvement: | unset |
---|
PR: https://github.com/django/django/pull/9323