除了在我的视图中在每个操作中声明以下检查之外,还有其他方法可以检查身份验证。
if request.user.is_authenticated():
# Do something for authenticated users.
else:
# Do something for anonymous users.
我想避免对我的所有视图操作执行此操作,是否有某种 @Decorators 可以与提供的 auth.login 一起使用,以在用户获得访问权限之前检查身份验证。
除了在我的视图中在每个操作中声明以下检查之外,还有其他方法可以检查身份验证。
if request.user.is_authenticated():
# Do something for authenticated users.
else:
# Do something for anonymous users.
我想避免对我的所有视图操作执行此操作,是否有某种 @Decorators 可以与提供的 auth.login 一起使用,以在用户获得访问权限之前检查身份验证。
您可能需要 login_required 装饰器
https://docs.djangoproject.com/en/1.5/topics/auth/default/#the-login-required-decorator