#21988 closed New feature (worksforme)
reverse() shouldn't require kwargs for uniquely determined named groups
Reported by: | Chris Jerdonek | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | chris.jerdonek@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For DRY purposes, it can be useful to capture a known substring in an URL for access from a view. For example--
url(r'^(?P<action>create)/confirm/$', ConfirmCreateView.as_view(), name='confirm_create') url(r'^(?P<action>change)/confirm/$', ConfirmChangeView.as_view(), name='confirm_change')
Calling reverse()
for examples like the above still requires passing the keyword argument though (action='create'
or action='change'
in these examples), even though the value of the keyword argument isn't necessary to construct the corresponding URL. This makes calling reverse()
less DRY than it needs to be.
I would like to suggest making reverse()
not require the keyword arguments in cases where the corresponding named groups have only one possible value. If this isn't possible to add, are there any suggestions for a DRY way to accomplish the same thing?
Change History (4)
comment:1 by , 11 years ago
Cc: | added |
---|
comment:2 by , 11 years ago
comment:3 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:4 by , 11 years ago
Thanks for the suggestion, @mjtamlyn. It's not quite as DRY as the proposed feature (there is an extra occurrence of the action name), but it is a good solution.
I don't think it would be possible (or reasonable) to detect this pattern out of the regex. However, there is already a way to achieve this without the DRY issues: