【发布时间】:2021-12-31 08:12:45
【问题描述】:
扩展自:Drf how to: simple-jwt authenticating without the USERNAME_FIELD
我试图弄清楚如何使用未设置为 USERNAME_FIELD 的字段对用户进行身份验证并遇到一些问题,它让我可以输入正确的数据字段,但它从不进行身份验证
我正在使用之前问题答案中的这个 sn-p:
class MyTokenStudentSerializer(TokenObtainPairSerializer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['student_id'] = serializers.CharField(required=False)
# self.fields['password'] = serializers.CharField(write_only=True, required=True)
self.fields['password'] = PasswordField(trim_whitespace=False)
username_field = 'student_id'
auth_fields = ['student_id']
#login view extended from TokenObtainPairView
class LoginStudentView(TokenObtainPairView):
permission_classes = (AllowAny,)
serializer_class = MyTokenStudentSerializer
生产
{
"detail": "No active account found with the given credentials"
}
任何修改将不胜感激。
【问题讨论】:
标签: django django-rest-framework django-authentication django-rest-framework-simplejwt