User Accounts
423
authentication views look for templates
inside a folder called registration, so
we’ll need to make that folder. Inside the
learning_log/users/ directory, make
a
directory called templates; inside that,
make another directory called reg-
istration. Here’s the
login.html template, which you should save in
learning_log
/users/templates/registration:
{% extends "learning_logs/base.html" %}
{% block content %}
u
{% if form.errors %}
Your username and password didn't match. Please try again.
{% endif %}
v
{% endblock content %}
This template extends
base.html to ensure that
the login page will have
the same look and feel as the rest of the site. Note that a template in one
app can inherit from a template in another app.
If the form’s
errors
attribute is set,
we display an error message u, report-
ing that the username and password combination don’t
match anything
stored in the database.
We want the login view to process the form,
so we set the
action
argument
as the URL of the login page v. The login view sends a form to the template,
and it’s up to us to display the form w and add a submit button x. At y
we
include a hidden form element,
'next'
; the
value
argument tells Django
where to redirect the user after they’ve logged in successfully. In this case,
we send the user back to the home page.
Do'stlaringiz bilan baham: