#17361 closed New feature (wontfix)
Add a way to reverse URLs for callables
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.syndication | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It is impossible to get reverse URL for a mapping defined like the one below:
(r'^rss/all$', codereview.feeds.AllFeed()),
{%url codereview.feeds.AllFeed %}
in template gives the following error:
NoReverseMatch while rendering: Reverse for 'codereview.feeds.AllFeed' with arguments '()' and keyword arguments '{}' not found. [TemplateSyntaxError]
Change History (5)
follow-up: 5 comment:1 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Summary: | syndication framework: no way to reverse feed url → Add a way to reverse URLs for callables |
Type: | Bug → New feature |
(converting to feature request)
Is it possible to extract module name of the callable to build its full path to be used in reverse lookups?
comment:3 by , 13 years ago
This feature request has two very simple workarounds as pointed out by lukeplant. It also doesn't have a way of supporting a lambda, which is not an uncommon use case. This also seems to be a lot more fragile than simply giving the url a name.
comment:4 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | reopened → closed |
I don't think there's any reason to adopt the maintenance burden for the code that would be needed to do this. Named urls are the preferred method for reversing.
comment:5 by , 13 years ago
Replying to lukeplant:
Yes, I believe it is impossible to reverse URLs defined only by a callable in the template. The solution is to either:
1) refer to your view by a string (dotted path) - which is possible in this case if you do something like
codereview_feeds = codereview.feeds.AllFeed()
in the relevant views.py. Or:
I need to refer to codereview.feeds.AllFeed() from base template, which is inherited by many views. Cooking this variable in every view is ugly.
2) Give your URL a name.
That's also ugly, because it duplicates the code for every view. I looked at the code that does URL reversing and IMO it is overarchitectured, so I am not surprised you're not too enthusiastic to support that.
BTW, I am not the first to ask about reverse URLs for syndication framework:
Yes, I believe it is impossible to reverse URLs defined only by a callable in the template. The solution is to either:
1) refer to your view by a string (dotted path) - which is possible in this case if you do something like
codereview_feeds = codereview.feeds.AllFeed()
in the relevant views.py. Or:2) Give your URL a name.