0

Is there a way to check authentication other than declaring the following check in each action in my views.

if request.user.is_authenticated():
    # Do something for authenticated users.
else:
    # Do something for anonymous users.

I would like to avoid having to do this for all my view actions, is there some sort of @Decorators that can be used with the provided auth.login to check authentication before user is given access.

1 Answer 1

2

You probably want the login_required decorator

https://docs.djangoproject.com/en/1.5/topics/auth/default/#the-login-required-decorator

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.