AccessMixin
Abstract CBV mixin that gives access mixins the same customizable functionality.
Attributes
| Attribute | Type | Description |
|---|---|---|
| login_url | string | The URL where users are redirected for login if they lack required permissions. |
| permission_denied_message | string | The message to be displayed or included in the exception when access is forbidden. |
| raise_exception | boolean = false | A boolean flag that determines whether to raise a PermissionDenied exception instead of redirecting to the login page. |
| redirect_field_name | string = REDIRECT_FIELD_NAME | The name of the query parameter that will contain the URL the user should be sent to after a successful login. |
Methods
get_login_url()
@classmethod
def get_login_url() - > string
Override this method to override the login_url attribute.
Returns
| Type | Description |
|---|---|
string | The URL string where users are redirected for authentication, falling back to settings.LOGIN_URL. |
get_permission_denied_message()
@classmethod
def get_permission_denied_message() - > string
Override this method to override the permission_denied_message attribute.
Returns
| Type | Description |
|---|---|
string | The message string to be displayed or raised when a user is denied access to the view. |
get_redirect_field_name()
@classmethod
def get_redirect_field_name() - > string
Override this method to override the redirect_field_name attribute.
Returns
| Type | Description |
|---|---|
string | The name of the query parameter used to store the URL the user should be sent to after successful login. |
handle_no_permission()
@classmethod
def handle_no_permission() - > [HttpResponseRedirect](../../../http/response/httpresponseredirect.md?sid=django_http_response_httpresponseredirect)
Handles requests when the user does not have the required permissions by either raising a PermissionDenied exception or redirecting to the login page.
Returns
| Type | Description |
|---|---|
[HttpResponseRedirect](../../../http/response/httpresponseredirect.md?sid=django_http_response_httpresponseredirect) | A redirect response to the login URL, including the current path as a redirect parameter if applicable. |