我继承了ObtainJSONWebToken并试图覆盖JSONWebTokenAPIView的post方法,但每次我点击API都会抛出错误:禁止(CSRF令牌丢失或不正确。):/myurl/
视图.py
from rest_framework_jwt.views import ObtainJSONWebToken
class LoginDrfJwtView(ObtainJSONWebToken):
def post(self, request, *args, **kwargs):
response = super(ObtainJSONWebToken, self).post(request, *args, **kwargs)
if condition == True:
# my code
return True
设置.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
JWT_AUTH = {
'JWT_AUTH_HEADER_PREFIX': 'JWT',
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300)
}
网址.py
from django.urls import path
from . import views
urlpatterns = [
path('login-jwt-over/', views.LoginDrfJwtView),
]