尝试按照Django 包含标记文档创建自定义模板标记,但在第 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>
我是否误解了如何创建包含标签和对象?感谢您的任何建议。