Skip to main content

AccessMixin

Abstract CBV mixin that gives access mixins the same customizable functionality.

Attributes

AttributeTypeDescription
login_urlstringThe URL where users are redirected for login if they lack required permissions.
permission_denied_messagestringThe message to be displayed or included in the exception when access is forbidden.
raise_exceptionboolean = falseA boolean flag that determines whether to raise a PermissionDenied exception instead of redirecting to the login page.
redirect_field_namestring = REDIRECT_FIELD_NAMEThe 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

TypeDescription
stringThe 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

TypeDescription
stringThe 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

TypeDescription
stringThe 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

TypeDescription
[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.