所以,我通过使用Tango Django这本书的教程中途尝试拼命地尽力获取尽可能多的关于Django的信息。在{%load rango_template_tags%}上打破模板
现在我想建立一个模板,列出所有类别的,但我得到一个错误
invalid syntax (rango_template_tags.py, line 8)
我不知道为什么我收到这条线,绝对没有我与书检查它5 +次,但我无法找到任何看起来不对的地方。任何人都可以告诉我为什么我得到这个错误。
base.html文件
{% load rango_template_tags %}
<div>
{% block sidebar_block %}
{% get_category_list %}
{% endblock %}
</div>
# This file has more within it these are the new pieces of code that break the template system. If these are in it wont work.
rango_template_tags
from django import template
from rango.models import Category
register = template.Library()
@register.inclusion_tag('rango/cats.html')
def get_category_list():
return {'cats' Category.objects.all()}
cats.html
<ul>
{% if cats %}
{% for c in cats %}
<li><a href="{% url 'show_category' c.slug %}">{{ c.name }}</a></li>
{% endfor %}
{% else %}
<li><strong> There ar eno categories presen. </strong></li>
{% endif %}
</ul>
该行至少有两个错误。再检查一遍。 –
@DanielRoseman你可以进一步细谈吗? –
你用书5 +次检查过,我不知道那本书是哪本书?缩进'return'行并在字典键(''cats'')后面加上冒号。 – Selcuk