名为’content’的Django’block’标签出现不止一次

我在制作应用程序时遇到此错误,我认为问题位于我的login.html中,因为它指向错误表.是因为我有2个{%block content%}它有冲突吗?感谢你们对我的帮助

TemplateSyntaxError at /login/

'block' tag with name 'content' appears more than once

Request Method:     GET
Request URL:    http://127.0.0.1:8000/login/
Django Version:     1.4.3
Exception Type:     TemplateSyntaxError
Exception Value:    

'block' tag with name 'content' appears more than once

Error during template rendering

In template C:\djcode\mysite\drinker\templates\login.html, error at line 21
'block' tag with name 'content' appears more than once
11  <div class="register_div">
12  {% if form.password.errors %}<p class="error">{{ form.password.errors }}</p>{%     endif %}
13  <p><label for="password"{% if form.password.errors %} class="error"{% endif %}>Password:</label></p>
14  <p>{{ form.password }}</p>
15  </div>
16  <p><input type="submit" alt="register" /></p>
17  </form>
18  <p>Forgot your password? <a href="/resetpassword/">Reset it!</a></p>
19  {% endblock %}
20  {% extends "base.html" %}
21  {% block content %}

我的login.html

 {% extends "base.html" %}
 {% block content %}
 <form action="" method="post">
 {% csrf_token %}
 {% if form.errors %}<p>Please correct the following fields:</p>{% endif %}
 <div class="register_div">
         {% if form.username.errors %}<p class="error">{{ form.username.errors }}</p>{% endif %}
         <p><label for="username"{% if form.username.errors %} class="error"{% endif %}>Username:</label></p>
         <p>{{ form.username }}</p>
 </div>
 <div class="register_div">
         {% if form.password.errors %}<p class="error">{{ form.password.errors }}</p>{% endif %}
         <p><label for="password"{% if form.password.errors %} class="error"{% endif %}>Password:</label></p>
         <p>{{ form.password }}</p>
 </div>
 <p><input type="submit" alt="register" /></p>
 </form>
 <p>Forgot your password? <a href="/resetpassword/">Reset it!</a></p>
 {% endblock %}

我还有一个链接到我的views.py的追溯

    Traceback Switch to copy-and-paste view

    C:\Python26\Lib\site-packages\django\core\handlers\base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)

    ...
    ▶ Local vars
    C:\djcode\mysite\drinker\views.py in LoginRequest

                        return render_to_response('login.html', context,     context_instance=RequestContext(request))

    ...
    ▶ Local vars 

最佳答案 是的,错误很明显:你有两个名为“content”的块.

说实话,我无法理解你在做什么,因为第二块看起来与第一块完全相同.你也不能有两个扩展标签.

点赞