我们使用django-rest-framework和django-rest-framework-jwt进行身份验证,除了django管理页面之外,它可以在任何地方使用ip:port/admin/.那仍然需要用户名和密码.
是否有设置或方法绕过它,以便它识别JWT?
/admin/页面是否总是需要使用名称/密码?我认为内置令牌auth可以使用它.
jwt是settings.py文件中唯一的auth设置.会话身份验证不再存在.
我想这更像是一个代码质量问题,但它确实涉及处理未处理的异常是 Django rest 框架。
删除受保护的记录只是返回<h1>500 internal server error<h1>
所以我添加了示例自定义异常处理程序。第一行返回一个无响应。
response = exception_handler(exc, context)
from rest_framework.views import exception_handler
from rest_framework.response import Response
from rest_framework import status
def custom_exception_handler(exc, context):
response = exception_handler(exc, context)
if response is None:
#DRF could not process the exception so we will treat it as a 500 and try to get the user as much info as possible.
response = Response({'error': str(exc)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return response
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,我将其视为 500,因为 DRF 无法处理exc.
我想我的问题是这是一种合适的处理方式吗,有没有人有这方面的经验有更好的解决方案?
更新:
Traceback:
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" …Run Code Online (Sandbox Code Playgroud)