I'm new to Django and I'm trying to create a login page.
Here's (part of) my urls.py file:
urlpatterns = patterns('',
(r'^$', main_page),
(r'^login/$', 'django.contrib.auth.views.login'),
)
And here's the template for my login page (registration/login.html):
<html>
<head>
<title>User Login</title>
</head>
<body>
<h1>User Login</h1>
{% if form.errors %}
<p>username and password don't match.</p>
{% endif %}
<form method="post" action=".">
<p>
<label for="id_username">Username:</label>
{% form.username %}
</p>
<p>
<label for="id_password">Password:</label>
{% form.password %}
</p>
<input type="hidden" name="next" value="/" />
<input type="submit" name="login" />
</form>
</body>
</html>
When I start the application and go to login.html I receive the following error message:
TemplateSyntaxError at /login/
Invalid block tag: 'form.username'
I don't understand what went wrong. As far as I know, the login view is supposed to load this template and pass the form
object. When printed, the form.username
attribute is supposed to generate HTML code for the username text field. Why doesn't that happen?
form
is a context variable, not a template tag. So access it via {{ form }}
or {{ form.username }}
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With