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
- If user is not authenticated, redirects to login (like
@login_required) - 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
- 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
- Checks if user authenticated recently (based on session timestamp)
- If not, raises
ReauthenticationRequiredexception - User is redirected to reauthentication page
- 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
- If user is authenticated:
- Checks if user is staff and active
- Raises
PermissionDeniedif not staff or not active - Allows access if user is staff and active
- 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(ifEMAIL_VERIFICATION_BY_CODE_ENABLED)
