Skip to main content

LoginView

Handles user login with support for multiple authentication methods.

Attributes

form_class
type
default:"LoginForm"
Form class to use for login.
template_name
str
Template path. Defaults to account/login.html or .txt based on TEMPLATE_EXTENSION.
success_url
str
URL to redirect after successful login.

Decorators

  • @rate_limit(action="login") - Rate limits login attempts
  • @login_not_required - Allows anonymous access
  • @sensitive_post_parameters - Protects password in error reports
  • @never_cache - Prevents caching

Methods

get_form_class()

Returns the form class, respecting FORMS setting.

form_valid(form)

Handles successful form submission.
form
LoginForm
The validated form.
return
HttpResponse
Response object (typically redirect).

Context Data

signup_url
str
URL to signup page.
site
Site
Current site object.
SOCIALACCOUNT_ENABLED
bool
Whether social authentication is enabled.
LOGIN_BY_CODE_ENABLED
bool
Whether passwordless login is enabled.
PASSKEY_LOGIN_ENABLED
bool
Whether passkey login is enabled.

Usage

# urls.py
from allauth.account.views import LoginView

urlpatterns = [
    path('login/', LoginView.as_view(), name='account_login'),
]

SignupView

Handles user registration.

Attributes

form_class
type
default:"SignupForm"
Form class to use for signup.
template_name
str
Template path. Defaults to account/signup.html or .txt.

Decorators

  • @rate_limit(action="signup") - Rate limits signup attempts
  • @login_not_required - Allows anonymous access
  • @sensitive_post_parameters - Protects password in error reports
  • @never_cache - Prevents caching

Methods

get_form_class()

Returns form class from settings or default.

form_valid(form)

Creates user and completes signup flow.

get_initial()

Pre-fills email from query parameter if provided.

Context Data

login_url
str
URL to login page.
signup_url
str
Current signup URL.
PASSKEY_SIGNUP_ENABLED
bool
Whether passkey signup is enabled.

ConfirmEmailView

Handles email confirmation via confirmation key.

Attributes

template_name
str
Template path. Defaults to account/email_confirm.html.

URL Parameters

key
str
Email confirmation key from URL.

Methods

get_object()

Retrieves EmailConfirmation from key.
return
EmailConfirmation
The confirmation object.

logout_other_user(confirmation)

Logs out current user if confirming for different account.
confirmation
EmailConfirmation
The confirmation being processed.

Context Data

confirmation
EmailConfirmation
The confirmation object.
can_confirm
bool
Whether confirmation can proceed.
email
str
Email address being confirmed.

EmailView

Manages user’s email addresses.

Attributes

form_class
type
default:"AddEmailForm"
Form for adding email addresses.
template_name
str
Template path. Uses account/email.html or account/email_change.html based on CHANGE_EMAIL setting.
success_url
str
default:"reverse_lazy('account_email')"
Redirect URL after actions.

Decorators

  • @login_required - Requires authenticated user
  • @rate_limit(action="manage_email") - Rate limits email operations

POST Actions

action_add
submit
Adds new email address.
action_send
submit
Resends verification email.
action_remove
submit
Removes email address.
action_primary
submit
Sets email as primary.

Context Data

emailaddresses
QuerySet
List of user’s email addresses.
can_add_email
bool
Whether user can add more emails.
new_emailaddress
EmailAddress
Pending new email (CHANGE_EMAIL mode).
current_emailaddress
EmailAddress
Current verified email (CHANGE_EMAIL mode).

PasswordChangeView

Handles password change for users with existing password.

Attributes

form_class
type
default:"ChangePasswordForm"
Form for changing password.
template_name
str
Template path. Defaults to account/password_change.html.

Decorators

  • @login_required - Requires authenticated user
  • @rate_limit(action="change_password") - Rate limits password changes
  • @sensitive_post_parameters - Protects passwords in error reports

Methods

dispatch(request, *args, **kwargs)

Redirects to PasswordSetView if user has no usable password.

get_default_success_url()

Returns redirect URL from adapter.

PasswordSetView

Handles password creation for users without existing password.

Attributes

form_class
type
default:"SetPasswordForm"
Form for setting password.
template_name
str
Template path. Defaults to account/password_set.html.

Decorators

  • @login_required - Requires authenticated user
  • @rate_limit(action="change_password") - Rate limits password operations
  • @sensitive_post_parameters - Protects passwords

PasswordResetView

Handles password reset request.

Attributes

form_class
type
default:"ResetPasswordForm"
Form for requesting password reset.
template_name
str
Template path. Defaults to account/password_reset.html.
success_url
str
default:"reverse_lazy('account_reset_password_done')"
Redirect URL after request.

Decorators

  • @login_not_required - Allows anonymous access

Methods

form_valid(form)

Sends password reset email with rate limiting.

PasswordResetFromKeyView

Handles password reset with key/token.

Attributes

form_class
type
default:"ResetPasswordKeyForm"
Form for resetting password.
template_name
str
Template path. Defaults to account/password_reset_from_key.html.
success_url
str
Success redirect URL.
reset_url_key
str
default:"set-password"
URL key for reset action.

URL Parameters

uidb36
str
Base36-encoded user ID.
key
str
Password reset token.

Decorators

  • @rate_limit(action="reset_password_from_key") - Rate limits reset attempts
  • @login_not_required - Allows anonymous access

LogoutView

Handles user logout.

Attributes

template_name
str
Template path. Defaults to account/logout.html.

Methods

get(request)

Handles GET requests. Logs out immediately if LOGOUT_ON_GET is True.

post(request)

Handles logout confirmation.

get_redirect_url()

Returns logout redirect URL from adapter.

ReauthenticateView

Requires user to confirm their password.

Attributes

form_class
type
default:"ReauthenticateForm"
Form for reauthentication.
template_name
str
Template path. Defaults to account/reauthenticate.html.

Decorators

  • @login_required - Requires authenticated user
  • Rate limited via _check_ratelimit method

Context Data

reauthentication_alternatives
list
Alternative reauthentication methods (e.g., TOTP, WebAuthn).

RequestLoginCodeView

Requests a login code for passwordless authentication.

Attributes

form_class
type
default:"RequestLoginCodeForm"
Form for requesting code.
template_name
str
Template path. Defaults to account/request_login_code.html.

Methods

form_valid(form)

Initiates login code verification process.

ConfirmLoginCodeView

Verifies login code for passwordless authentication.

Attributes

form_class
type
default:"ConfirmLoginCodeForm"
Form for code verification.
template_name
str
Template path. Defaults to account/confirm_login_code.html.

Decorators

  • @login_stage_required - Requires active login stage
  • @never_cache - Prevents caching

Context Data

email
str
Email where code was sent.
phone
str
Phone where code was sent.

ChangePhoneView

Handles phone number changes.

Attributes

form_class
type
default:"ChangePhoneForm"
Form for changing phone.
template_name
str
Template path. Defaults to account/phone_change.html.
success_url
str
default:"reverse_lazy('account_verify_phone')"
Redirect to phone verification.

Decorators

  • @login_required - Requires authenticated user
  • @rate_limit(action="change_phone") - Rate limits phone changes

Context Data

phone
str
Current phone number.
phone_verified
bool
Whether phone is verified.

Function-Based View Shortcuts

These are convenience references to class-based views:
login = LoginView.as_view()
signup = SignupView.as_view()
confirm_email = ConfirmEmailView.as_view()
email = EmailView.as_view()
password_change = PasswordChangeView.as_view()
password_set = PasswordSetView.as_view()
password_reset = PasswordResetView.as_view()
password_reset_from_key = PasswordResetFromKeyView.as_view()
logout = LogoutView.as_view()
reauthenticate = ReauthenticateView.as_view()
request_login_code = RequestLoginCodeView.as_view()
confirm_login_code = ConfirmLoginCodeView.as_view()
change_phone = ChangePhoneView.as_view()

Usage Examples

Custom Login View

from allauth.account.views import LoginView
from .forms import CustomLoginForm

class MyLoginView(LoginView):
    form_class = CustomLoginForm
    template_name = 'myapp/login.html'
    
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['custom_data'] = 'value'
        return context

Overriding Success URL

from allauth.account.views import SignupView
from django.urls import reverse_lazy

class MySignupView(SignupView):
    success_url = reverse_lazy('welcome')

URL Configuration

from django.urls import path, include
from allauth.account import views

urlpatterns = [
    path('accounts/login/', views.login, name='account_login'),
    path('accounts/signup/', views.signup, name='account_signup'),
    path('accounts/logout/', views.logout, name='account_logout'),
    path('accounts/password/change/', views.password_change, name='account_change_password'),
    path('accounts/email/', views.email, name='account_email'),
    # Or use the default URLs:
    path('accounts/', include('allauth.urls')),
]

Build docs developers (and LLMs) love