views:

187

answers:

2

I am having trouble doing a reverse URL lookup for Django-generated feeds.

I have the following setup in urls.py:

feeds = {
    'latest': LatestEntries,
}

urlpatterns = patterns('',
    # ...
    # enable feeds (RSS)
    url(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
        {'feed_dict': feeds}, name='feeds_view'),
)

I have tried using the following template tag:

<a href="{% url feeds_view latest %}">RSS feeds</a>

But the resulting link is not what want (http://my.domain.com/feeds//). It should be http://my.domain.com/feeds/latest/.

For now, I am using a hack to generate the URL for the template:

<a href="http://{{ request.META.HTTP_HOST }}/feeds/latest">RSS feeds</a>

But, as you can see, it clearly is not DRY. Is there something I am missing?

+1  A: 

You're using keyword arguments so you should pass them as such :) Try this:

<a href="{% url feeds_view url="latest" %}">RSS feeds</a>
WoLpH
+3  A: 

Unfortunately, URL reversing is not really possible with the current feed framework. The good news is that the feed framework has been completely refactored and can seamlessly integrate with Django's URL resolving mechanisms. This refactored feed framework will be delivered with Django 1.2, which should arrive at the end of April. You can read up on it in the docs or in a great article by Rob Hudson on DjangoAdvent.

piquadrat
Great article. Thanks. The suggestion below works, though.
Santa