【发布时间】:2012-06-07 16:01:45
【问题描述】:
我无法将我的问题放在一句话中。 我正在按照教程从头开始制作博客。但本教程预测在单独的模板中列出所有类别、标签、月份和年份。
我想在主博客页面上添加类别列表、月份和年份列表。
这就是我得到的。使用此代码,类别列表会显示在主页中,但前提是您转到 blog/category url,而不仅仅是 blog/ 我想要的位置。
**(r'^$', list),**
(r'^archive/(\d{1,2})/$', list),
(r'^\d{2}/d{4}/$', month),
(r'^([0-9]{4}/\d{1,2})/(?P<slug>.*)/$', detail),
(r'^(?P<year>\d{4})/$', year),
**(r'^category/$', category),**
我也试过了:
(r'^$', category),
但没有运气。
这是 category.html 和 list.html 中模板中的相同代码:
{% if categories %}
{% for category in categories %}
<li class="cat-item"><a href="category/{{ category.name.lower }}/"
title="{{ category.name.capitalize }}">
{{ category.name.capitalize }}</a>
</li>
{% endfor %}
{% endif %}
Views.py:
def category(request):
return render_to_response('blog/list.html', {'categories':Category.objects.all(),},)
是这样的。我试过这个,但在 def list 中没有运气:
return render_to_response('blog/list.html',{'posts':posts,
'next':next,
'previous':previous,
'categories':Category.objects.all(),
},)
我怎样才能让博客/类别上显示的内容也显示在博客/上? 谢谢。
【问题讨论】:
-
list是 Python 内置函数。我不建议为您的视图列表命名,因为它会影响内置。
标签: django function blogs categories