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

Comments

yedpodtrzitko (on June 26, 2012):
<p>There's no way how this can works - you call dispatch() from parent, but parent of this class (object) doesn't have dispatch() method.</p>

#

liangsun (on January 10, 2013):
<p>It's a Mixin, baby.</p>

#

Please login first before commenting.