Issue
I want to open my login view only to non logged in users. means once user is logged in, he/she can not access login view by hitting /login/ url manually.
Thanks in advance :)
Solution
You can use @user_passes_test
:
from django.contrib.auth.decorators import user_passes_test
def user_is_not_logged_in(user):
return not user.is_authenticated()
@user_passes_test(user_is_not_logged_in)
def my_view(request):
...
You can use @user_passes_test(user_is_not_logged_in, login_url='/')
to redirect to another URL and avoid server errors.
Answered By - Francisco
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.