我目前正在Django 1.3.1上做一些启动,并且跟踪错误让我感到震惊了2个小时。帮我弄清楚错误。我已将代码包含在bitbucket中。
错误: -
TemplateSyntaxError at /events/archive/
Invalid block tag: 'else', expected 'empty' or 'endfor'
模板错误
在模板/home/virus/py_tut/startthedark/startthedark/templates/events/archive.html中,第32行出错
无效的块标记:'else',预期'empty'或'endfor'
22 {% csrf_token %}
23 <input type="hidden" name="event_id" value="{{event.id}}"/>
24 {% if attending %}
25 <input class="attendance unattend" type = "submit" value = "Unattend" />
26 {% else %}
27 <input class = "attendance attend" type ="submit" value = "Attend"/>
28 {% endif %}
29 </form>
30 -->
31 {% endfor %}
32 {% else %}
33 <p>No events for today.</p>
34 {% endif %}
35
36 {% endblock %}
37
Archive.html
{% extends "base.html" %}
{% load events_tags %}
{% block title %}Archive -{{ block.super}}{% endblock %}
{% block main_content %}
<a href="{% url ev_create %}">Create an Event</a>
{% if events %}
{% for e in events %}
{% event e %}
{% endfor %}
{% else %}
<p>No events for today.</p>
{% endif %}
{% endblock %}
events_tags.py
from django import template
from events.models import Attendance
def event(context, e):
to_return = {
'event' : e,
#'request': context['request'],
}
if context['user'].is_authenticated():
try:
Attendance.objects.get(event=e,user = context['user'])#request.user)
attending = True
except Attendance.DoesNotExist:
attending = False
to_return.update({
'attending':attending,
'authenticated':True,
})
else:
to_return['authenticated'] = False
return to_return
register = template.Library()
register.inclusion_tag('events/event.html',takes_context=True)(event)
答案 0 :(得分:4)
评论标记即&lt;! - 评论 - &gt;是HTML评论。 Django不认识他们。如果你在注释块中包含模板标签,Django会处理它们而不是忽略它们。
对于Django中的多行注释,请使用:
{% comment %}
......
........
{% endcomment %}