Warz
Warz

Reputation: 7746

check user authentication on every action request with Django

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.

Upvotes: 0

Views: 240

Answers (1)

Ted
Ted

Reputation: 12318

You probably want the login_required decorator

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

Upvotes: 2

Related Questions