【发布时间】:2012-07-15 04:47:38
【问题描述】:
尝试按照 Django Inclusion Tag documentation 创建自定义模板标签,但在第 6 行收到模板语法错误:def types(Information)。
from django import template
register = template.Library()
@register.inclusion_tag('edit.html')
def types(Information)
informations = Information.objects.all()
return {'informations': informations}
templatetag.py 文件位于/templatetags 目录中。
信息模型:
class Information(models.Model):
name = models.CharField(max_length=20)
models = models.ManyToManyField('Model')
模板(edit.html):
{% load templatetag %}
<ul>
{% for information in informations %}
<li> {{ information }} </li>
{% endfor %}
</ul>
我是否误解了如何创建包含标签和对象?感谢您的建议。
【问题讨论】:
标签: python django templates object tags