Skip to main content

verified_email_required

Decorator that ensures the user is authenticated and has at least one verified email address.

Parameters

callable
The view function to decorate. Can be omitted when using decorator with arguments.
str
URL to redirect to if user is not authenticated. Defaults to settings.LOGIN_URL.
str
default:"'next'"
Name of the query parameter for the redirect URL.

Behavior

  1. If user is not authenticated, redirects to login (like @login_required)
  2. If user is authenticated but has no verified email:
    • Automatically resends verification email
    • Shows verification required page or redirects to code entry if EMAIL_VERIFICATION_BY_CODE_ENABLED
  3. If user has verified email, allows access to view

Usage

With Custom Login URL

With Custom Redirect Field

Class-Based Views


reauthentication_required

Decorator that requires the user to have recently authenticated. Useful for sensitive operations.

Parameters

callable
The view function to decorate.
str
default:"'next'"
Name of the query parameter for the redirect URL.
bool
default:"False"
Whether to allow GET requests without reauthentication.
bool | callable
Control whether reauthentication is required. Can be a boolean or callable that accepts request and returns bool.

Behavior

  1. Checks if user authenticated recently (based on session timestamp)
  2. If not, raises ReauthenticationRequired exception
  3. User is redirected to reauthentication page
  4. After reauthenticating, user is redirected back to original view

Usage

Allow GET Requests

Conditional Reauthentication

Always Disabled


secure_admin_login

Decorator for securing admin login views. Ensures only staff members can access admin login.

Parameters

callable
The view function to decorate.

Behavior

  1. If user is authenticated:
    • Checks if user is staff and active
    • Raises PermissionDenied if not staff or not active
    • Allows access if user is staff and active
  2. If user is not authenticated:
    • Redirects to login URL with next parameter

Usage

Custom Admin Login View


Complete Usage Examples

Combining Decorators

Premium Feature Gate

Conditional Reauthentication by Value

Class-Based View Examples

API View Protection

Integration with Settings

Configure Reauthentication Timeout

Email Verification Templates

When @verified_email_required blocks a user, it renders:
  • account/verified_email_required.html (if using template response)
  • Or redirects to account_email_verification_sent (if EMAIL_VERIFICATION_BY_CODE_ENABLED)
Customize these templates to match your design: