Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Add error message in django loginrequiredmixin

class CustomLoginRequiredMixin(LoginRequiredMixin):
""" The LoginRequiredMixin extended to add a relevant message to the
messages framework by setting the ``permission_denied_message``
attribute. """

permission_denied_message = 'You have to be logged in to access that page'

def dispatch(self, request, *args, **kwargs):
    if not request.user.is_authenticated:
        messages.add_message(request, messages.WARNING,
                             self.permission_denied_message)
        return self.handle_no_permission()
    return super(CustomLoginRequiredMixin, self).dispatch(
        request, *args, **kwargs
    )
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Add #error #message #django #loginrequiredmixin
ADD COMMENT
Topic
Name
5+6 =