我正在使用rest_framework_simplejwt对我的用户进行身份验证,但是在某些视图中我需要忽略它,因为这些是公共视图。我想将令牌检查到视图流中。预期的行为是:
在公众视野中
实际上rest_framework_simplejwt检查令牌并401在令牌无效或过期时引发......
我尝试authentication_classes在 APIView 中像这样禁用:
class SpecificProductApi(APIView):
def get_authenticators(self):
if self.request.method == 'GET':
self.authentication_classes = []
return super(SpecificProductApi, self).get_authenticators()
Run Code Online (Sandbox Code Playgroud)
但是如果我在输入GET APIView方法之前禁用它,我不能这样做,if reques.user.is_authenticated:因为我禁用了令牌:(
是否存在启用进入 api http 方法并手动检查用户查看的方法?谢谢
django python-3.x django-rest-framework jwt-auth django-rest-framework-simplejwt