【发布时间】:2011-01-23 03:06:09
【问题描述】:
我正在尝试构建自己的模板标签。 我不知道为什么会出现这些错误。我正在关注 Django 文档。
这是我应用的文件结构:
pollquiz/
__init__.py
show_pollquiz.html
showpollquiz.py
这是 showpollquiz.py:
from django import template
from pollquiz.models import PollQuiz, Choice
register = template.Library()
@register.inclusion_tag('show_pollquiz.html')
def show_poll():
poll = Choice.objects.all()
return { 'poll' : poll }
html 文件:
<ul>
{% for poll in poll
<li>{{ poll.pollquiz }}</li>
{% endfor
</ul>
在我的 base.html 文件中,我包含这样的内容
{% load showpollquiz %}
and
{% poll_quiz %}
然后我得到错误:
Exception Value: Caught an exception while rendering: show_pollquiz.html
我不知道为什么会这样。有任何想法吗?请记住,我还是 Django 的新手
【问题讨论】:
-
教程完成了吗?你在扩展教程吗?有几件事对我来说看起来很奇怪(您将模板与 Python 代码保存在同一目录中,您有一个名为
show_poll的包含标记,但我看不出您在哪里使用它 - 您正在使用名为poll_quiz的自定义标签)。