无效的块标记,预期的'endblock'

时间:2014-07-07 14:51:07

标签: python django

我知道这个问题已经遍布stackoverflow,但是它的这个特殊实例让我迷失了。原因是,我定期收到此错误 - 根本不更改HTML文件。

问题似乎在这里:

{% extends "base.html" %}
{% load static %}
{% load support_tags %}

{% block content_header %}
<h1>Header</h1>
{% endblock content_header %}

{% block new-main-area %}
        {% ticket_categories as categories %} {# Problem is here #}
            <option value="None">Select a Category</option>
        {% for cat in categories %}
            <option value="{{cat.slug}}">{{cat}}</option>
        {% endfor %}
{% endblock new-main-area %}

{% block extrascripts_bottom %}
{% endblock extrascripts_bottom %}

谢谢!

1 个答案:

答案 0 :(得分:3)

恕我直言,代码滥用了with标签:

替换以下行:

{% ticket_categories as categories %} <!-- Problem is here -->
    <option value="None">Select a Category</option>
{% for cat in categories %}
    <option value="{{cat.slug}}">{{cat}}</option>
{% endfor %}

使用:

{% with ticket_categories as categories %} <!-- Problem is here -->
    <option value="None">Select a Category</option>
{% for cat in categories %}
    <option value="{{cat.slug}}">{{cat}}</option>
{% endfor %}
{% endwith %}

或者(根本不需要with):

<option value="None">Select a Category</option>
{% for cat in ticket_categories %}
    <option value="{{cat.slug}}">{{cat}}</option>
{% endfor %}