What is the opposite of @login_required decorator for Django views?

后端 未结 6 2074
耶瑟儿~
耶瑟儿~ 2020-12-29 09:37

If I want to make sure that a view is listed as having public access, is there a decorator equivalent to @public_access which would be the opposite of @login_required and ma

6条回答
  •  旧巷少年郎
    2020-12-29 09:51

    A bit late, but another simple way to tackle this issue would be to rely on another decorator and add a lambda function:

    from django.contrib.auth.decorators import user_passes_test
    
    @user_passes_test(lambda u: u.is_anonymous)
    

提交回复
热议问题