Login

LoginRequiredMixin

Author:
slink
Posted:
May 20, 2011
Language:
Python
Version:
1.3
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. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 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.