class LoginRequiredMixin

from django.contrib.auth.mixins import LoginRequiredMixin
CBV mixin which verifies that the current user is authenticated.

Ancestors (MRO)

  1. LoginRequiredMixin
  2. AccessMixin

Attributes

  Defined in
login_url = None AccessMixin
permission_denied_message = '' AccessMixin
raise_exception = False AccessMixin
redirect_field_name = 'next' AccessMixin
Expand Collapse

Methods

def dispatch(self, request, *args, **kwargs): LoginRequiredMixin

53
54
55
56
def dispatch(self, request, *args, **kwargs):
    if not request.user.is_authenticated:
        return self.handle_no_permission()
    return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)

def get_login_url(self): AccessMixin

Override this method to override the login_url attribute.
19
20
21
22
23
24
25
26
27
28
29
def get_login_url(self):
    """
    Override this method to override the login_url attribute.
    """
    login_url = self.login_url or settings.LOGIN_URL
    if not login_url:
        raise ImproperlyConfigured(
            '{0} is missing the login_url attribute. Define {0}.login_url, settings.LOGIN_URL, or override '
            '{0}.get_login_url().'.format(self.__class__.__name__)
        )
    return force_text(login_url)

def get_permission_denied_message(self): AccessMixin

Override this method to override the permission_denied_message attribute.
31
32
33
34
35
def get_permission_denied_message(self):
    """
    Override this method to override the permission_denied_message attribute.
    """
    return self.permission_denied_message

def get_redirect_field_name(self): AccessMixin

Override this method to override the redirect_field_name attribute.
37
38
39
40
41
def get_redirect_field_name(self):
    """
    Override this method to override the redirect_field_name attribute.
    """
    return self.redirect_field_name

def handle_no_permission(self): AccessMixin

43
44
45
46
def handle_no_permission(self):
    if self.raise_exception:
        raise PermissionDenied(self.get_permission_denied_message())
    return redirect_to_login(self.request.get_full_path(), self.get_login_url(), self.get_redirect_field_name())