Login

Decorator @not_login_required

Author:
florent1933
Posted:
February 12, 2015
Language:
Python
Version:
1.7
Score:
1 (after 1 ratings)

This is a simple django snippet!

It is the opposite of @login_required decorator for Django views

Example

@not_login_required

def login_page(request): ...

1
2
3
4
5
6
7
8
9
from django.shortcuts import redirect

def not_login_required(f):
    def wrapped(request):
        if request.user.is_authenticated():
            return redirect('home')
        else:
            return f(request)
    return wrapped

More like this

  1. codigo alto nivel by MrRocklion 1 month ago
  2. Load template from specific app by Krzysiek555 1 month, 3 weeks ago
  3. PostgreSQL JSON subqueries by dolamroth 1 month, 3 weeks ago
  4. "Magic Link" Management Command by webology 6 months, 4 weeks ago
  5. Closest ORM models to a latitude/longitude point by simonw 6 months, 4 weeks ago

Comments

mlubimow (on February 20, 2015):

Nice but for me better name would be anonymous_required().

#

Please login first before commenting.