Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django

I got this error when making an app and I think the problem is located in my login.html as it points in the error sheet. Is it because I have 2 {% block content %} which it conflicts? Thank you for helping me

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 %}

My 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 %}

I also got a traceback linking to my 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 
like image 280
donkeyboy72 Avatar asked Feb 27 '13 12:02

donkeyboy72


2 Answers

Yes, the error is quite clear: you have two blocks named "content".

To be honest I can't understand what you're doing, as the second block seems to be an exact duplicate of the first. You can't have two extends tags either.

like image 143
Daniel Roseman Avatar answered Nov 10 '22 04:11

Daniel Roseman


You can do the things you want to in the back-end, ie:- Python. You can for example do something like:-

# 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 %}
like image 1
GURU RAJ Avatar answered Nov 10 '22 06:11

GURU RAJ