简体   繁体   English

Django:提要的反向查找URL?

[英]Django: reverse lookup URL of feeds?

I am having trouble doing a reverse URL lookup for Django-generated feeds. 我无法对Django生成的供稿进行反向URL查找。

I have the following setup in urls.py : 我在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// ). 但是结果链接不是想要的( http://my.domain.com/feeds// )。 It should be http://my.domain.com/feeds/latest/ . 它应该是http://my.domain.com/feeds/latest/

For now, I am using a hack to generate the URL for the template: 现在,我正在使用一种hack来生成模板的URL:

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

But, as you can see, it clearly is not DRY. 但是,正如您所看到的,它显然不是DRY。 Is there something I am missing? 我有什么想念的吗?

Unfortunately, URL reversing is not really possible with the current feed framework. 不幸的是,当前的提要框架实际上无法实现URL反向。 The good news is that the feed framework has been completely refactored and can seamlessly integrate with Django's URL resolving mechanisms. 好消息是,提要框架已经完全重构,并且可以与Django的URL解析机制无缝集成。 This refactored feed framework will be delivered with Django 1.2, which should arrive at the end of April . 这个重构的feed框架将随Django 1.2一起提供,该版本应于4月底到达。 You can read up on it in the docs or in a great article by Rob Hudson on DjangoAdvent . 您可以在文档中阅读它,也可以在RobHudsonDjangoAdvent上的精彩文章中 阅读

您正在使用关键字参数,因此您应该像这样传递它们:)尝试以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM