Django';区块';标记名称';内容';多次出现
我在制作应用程序时遇到了这个错误,我想问题出在我的login.html中,因为它指向了错误表。是因为我有2个{%block content%}冲突吗?谢谢你帮助我Django';区块';标记名称';内容';多次出现,django,Django,我在制作应用程序时遇到了这个错误,我想问题出在我的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 Vers
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 %}
是的,错误很明显:您有两个名为“content”的块
老实说,我不明白你在做什么,因为第二个区块似乎与第一个区块完全相同。您也不能有两个
扩展标记。您可以在后端做您想做的事情,即:-Python。
例如,您可以执行以下操作:-
# views.py::
if something is True(any condition for that matter)
msg = "something"
else:
msg = "Something else"
# template, it is here -- index.html::
{% block title %}{{msg}}{% endblock title %}
我习惯于先用谷歌搜索我的错误消息,然后再考虑它们,因为这样明显的错误消息太少了(我是django的新手),但我必须承认这一点非常清楚……如果我想在同一模板中用if语句分隔两个相同的块,该怎么办?这可能吗?@torostar不,还是不可能。您将得到相同的错误。
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
# views.py::
if something is True(any condition for that matter)
msg = "something"
else:
msg = "Something else"
# template, it is here -- index.html::
{% block title %}{{msg}}{% endblock title %}