📅  最后修改于: 2022-03-11 14:46:50.032000             🧑  作者: Mango
#by default, TokenObtainPairView takes 'username' and 'password' as user
#credentials. This snippet makes them 'email' and 'password'
#https://stackoverflow.com/questions/54157056/how-can-i-use-email-in-django-rest-framework-simplejwt-instead-of-username
from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.serializers import (
TokenObtainPairSerializer, User
)
class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
username_field = User.EMAIL_FIELD
class EmailTokenObtainPairView(TokenObtainPairView):
serializer_class = CustomTokenObtainPairSerializer