- 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
- Template tag - list punctuation for a list of items by shapiromatron 4 months ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 4 months, 1 week ago
- Serializer factory with Django Rest Framework by julio 11 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months, 3 weeks ago
- Help text hyperlinks by sa2812 1 year ago
Comments
Nice but for me better name would be
anonymous_required()
.#
Please login first before commenting.