Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17361 closed New feature (wontfix)

Add a way to reverse URLs for callables

Reported by: anatoly techtonik <techtonik@…> 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)

comment:1 by Luke Plant, 13 years ago

Resolution: invalid
Status: newclosed

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.

comment:2 by anatoly techtonik <techtonik@…>, 13 years ago

Resolution: invalid
Status: closedreopened
Summary: syndication framework: no way to reverse feed urlAdd a way to reverse URLs for callables
Type: BugNew 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 Michael Manfre, 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 Carl Meyer, 13 years ago

Resolution: wontfix
Status: reopenedclosed

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.

in reply to:  1 comment:5 by anatoly techtonik <techtonik@…>, 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:

  1. https://groups.google.com/forum/#!topic/django-users/Z9eJczJvtI8
  2. http://stackoverflow.com/questions/3402362/how-to-reverse-django-feed-url
  3. http://stackoverflow.com/questions/2604823/django-reverse-lookup-url-of-feeds
Note: See TracTickets for help on using tickets.
Back to Top