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.
我一直在寻找几个小时试图弄明白这一点,似乎没有人在网上举例 - 我刚刚创建了一个Django 1.2 rss feed视图对象并将其附加到一个url。当我访问网址时,一切都很好,所以我知道我的Feed类的实现是可以的。
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 %}
问题是,我无法弄清楚如何链接到我的模板中的网址。我可以硬编码,但我宁愿使用{%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:
这是相关的url模式:
from app.lib.feeds import LatestPosts
urlpatterns = patterns('app.blog.views',
(r'^rss/(?P<blog_name>[A-Za-z0-9]+)/$', LatestPosts()),
#snip...
)
Thanks for your help.
谢谢你的帮助。
1 个解决方案
#1
6
You can name your url pattern, which requires the use of the url
helper function:
您可以命名您的网址格式,这需要使用网址辅助功能:
from django.conf.urls.defaults import url, patterns
urlpatterns = patterns('app.blog.views',
url(r'^rss/(?P<blog_name>[A-Za-z0-9]+)/$', LatestPosts(), name='latest-posts'),
#snip...
)
Then, you can simply use {% url latest-posts blog_name="myblog" %}
in your template.
然后,您只需在模板中使用{%url latest-posts blog_name =“myblog”%}即可。
#1
6
You can name your url pattern, which requires the use of the url
helper function:
您可以命名您的网址格式,这需要使用网址辅助功能:
from django.conf.urls.defaults import url, patterns
urlpatterns = patterns('app.blog.views',
url(r'^rss/(?P<blog_name>[A-Za-z0-9]+)/$', LatestPosts(), name='latest-posts'),
#snip...
)
Then, you can simply use {% url latest-posts blog_name="myblog" %}
in your template.
然后,您只需在模板中使用{%url latest-posts blog_name =“myblog”%}即可。