Login

LoginRequiredMixin

Author:
slink
Posted:
May 20, 2011
Language:
Python
Version:
1.3
Tags:
view mixin class login-required
Score:
2 (after 2 ratings)

Provides a mixin view class that requires logged-in user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator


class LoginRequiredMixin(object):
    u"""Ensures that user must be authenticated in order to access view."""

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)

More like this

  1. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 6 months, 2 weeks ago
  2. Crispy Form by sourabhsinha396 7 months, 1 week ago
  3. ReadOnlySelect by mkoistinen 7 months, 3 weeks ago
  4. Verify events sent to your webhook endpoints by santos22 8 months, 2 weeks ago
  5. Django Language Middleware by agusmakmun 9 months ago

Comments

yedpodtrzitko (on June 26, 2012):

There's no way how this can works - you call dispatch() from parent, but parent of this class (object) doesn't have dispatch() method.

#

liangsun (on January 10, 2013):

It's a Mixin, baby.

#

Please login first before commenting.