1
試圖按照Django Inclusion Tag documentation創建自定義模板標記,但在第6行獲取模板語法錯誤:def types(Information)
。Django內含標記語法錯誤
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>
我誤解了如何創建包含標籤和對象?感謝您的任何建議。
該死的,再次感謝羅斯曼先生。不能相信我錯過了這一點。 – 2012-07-15 04:51:30