【发布时间】:2020-02-06 08:04:02
【问题描述】:
我刚刚在 Django 项目中安装了 django-rest-framework-simplejwt,如果我发送了无效的 Authentication Bearer <<token>> 标头,它会使用 401 代码阻止我的请求。这是预期的行为。问题是,如果我删除 Authentication 标头,我可以访问我的视图,因此它不受保护。
如果没有 Authentication 标头,如何保护视图返回 401?
查看代码如下:
class AuthTestView(views.APIView):
http_method_names = ['get']
def get(self, request):
response_data = {
'result': 'Restricted access test ok.',
}
return Response(data=response_data, status=status.HTTP_200_OK)
【问题讨论】:
标签: django django-rest-framework