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. Django BasicAuthMixin by icrni 8 months, 3 weeks ago
  2. Class-based view mixin for flatpages by schwuk 2 years ago
  3. View mixin and utils to generate PDF documents from html using xhtml2pdf by frankban 3 years, 5 months ago
  4. Basic PDF view mixin and utils using reportlab. by elequ 1 year, 7 months ago
  5. Seeded Randomized Querysets w/ Pagination Mixin by ScottBarkman 2 days, 21 hours 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.