Reputation:
I'm trying to learn Django and am trying to setup a user login system. My site only shows the base.html contents, and not the contents of login.html. If I remove the extends base.html, the login form seems to show up correctly. Am I doing something wrong?
login.html
{% extends "base.html" %}
{% load url from future %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
base.html
<body>
<div>
{{ user }}
{% if user.is_anonymous %}
<a href="{% url 'django.contrib.auth.views.login' %}">login</a>
{% else %}
<a href="{% url 'django.contrib.auth.views.logout' %}">logout</a>
{% endif %}
</div>
Upvotes: 0
Views: 271
Reputation: 574
Brandon is right.
you can think {%block content %} as a hole in your base.html and the extended file only replace/fill in that hole.
Upvotes: 0
Reputation: 34593
Your base.html
template is missing a corresponding {% block content %}{% endblock content %}
and also a closing </body>
tag. There's nowhere for the content in login.html
to go.
Upvotes: 1