Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Django - Authentication Views

Back


Authentication Views


django.contrib.auth.views Module

View Class Patterns Name
LoginView accounts/login/ login
LogoutView accounts/logout/ logout
PasswordChangeView accounts/password_change/ password_change
PasswordChangeDoneView accounts/password_change/done/ password_change_done
PasswordResetView accounts/password_reset/ password_reset
PasswordResetDoneView accounts/password_reset/done/ password_reset_done
PasswordResetCompleteView accounts/reset/<uidb64>/<token>/ password_reset_confirm
PasswordResetCompleteView accounts/reset/done/ password_reset_complete
Method Description
logout_then_login Log out the user if they are logged in. Then redirect to the login page.
redirect_to_login Redirect the user to the login page, passing the given ‘next’ page.

-/ extends "base.html" \-

-/ block content \-

-/ if form.errors \-
<p>Your username and password didn't match. Please try again.</p>
-/ endif \-

-/ if next \-
    -/ if user.is_authenticated \-
    <p>Your account doesn't have access to this page. To proceed,
    please login with an account that has access.</p>
    -/ else \-
    <p>Please login to see this page.</p>
    -/ endif \-
-/ endif \-

<form method="post" action="-/ url '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>

{# Assumes you set up the password_reset view in your URLconf #}
<p><a href="-/ url 'password_reset' \-">Lost password?</a></p>

-/ endblock \-

Built-in forms

Form Description
AdminPasswordChangeForm changes a user’s password in the admin interface
UserChangeForm change a user’s information and permissions in the admin interface
AuthenticationForm logs a user in.
PasswordChangeForm allows a user to change their password.
PasswordResetForm generates and emails a one-time use link to reset a user’s password.
SetPasswordForm lets a user change their password without entering the old password.
UserCreationForm creates a new user.

Authentication data in templates




Managing users in the admin


TOP