如何反转 django feed url?
我已经搜索了几个小时来尝试解决这个问题,似乎没有人在网上放过一个例子 - 我刚刚创建了一个 Django 1.2 rss feed 视图对象并将其附加到一个 url。当我访问该 url 时,一切正常,因此我知道我的 feed 类的实现是正常的。
问题是,我不知道如何链接到模板中的网址。我可以硬编码它,但我更愿意使用 {% url %}
我尝试过像这样传递完整路径:
{% url app_name.lib.feeds.LatestPosts blog_name=name %}
但我什么也没得到。我一直在搜索,似乎其他人都有一个显而易见的解决方案,不值得在网上发布。我刚刚起床太久了吗?
这是相关的 url 模式:
from app.lib.feeds import LatestPosts
urlpatterns = patterns('app.blog.views',
(r'^rss/(?P<blog_name>[A-Za-z0-9]+)/$', LatestPosts()),
#snip...
)
感谢您的帮助。
I've been searching for hours to try and figure this out, and it seems like no one has ever put an example online - I've just created a Django 1.2 rss feed view object and attached it to a url. When I visit the url, everything works great, so I know my implementation of the feed class is OK.
The hitch is, I can't figure out how to link to the url in my template. I could just hard code it, but I would much rather use {% url %}
I've tried passing the full path like so:
{% url app_name.lib.feeds.LatestPosts blog_name=name %}
And I get nothing. I've been searching and it seems like everyone else has a solution so obvious it's not worth posting online. Have I just been up too long?
Here is the relevent url pattern:
from app.lib.feeds import LatestPosts
urlpatterns = patterns('app.blog.views',
(r'^rss/(?P<blog_name>[A-Za-z0-9]+)/
Thanks for your help.
, LatestPosts()),
#snip...
)
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以命名您的网址模式,这需要使用
url
辅助函数的功能:然后,您只需在模板中使用
{% urllatest-posts blog_name="myblog" %}
即可。You can name your url pattern, which requires the use of the
url
helper function:Then, you can simply use
{% url latest-posts blog_name="myblog" %}
in your template.