I've explored how to add more information to the Response body and now would like to know how to customize the Payload data by adding iat claim, username and today's date.推荐答案由于您已经为所需视图(MyTokenObtainPairView)创建了一个子类,并为其对应的序列化器(MyTokenObtainPairSerializer)创建了一个子类,因此将以下内容添加到序列化器中As you already created a subclass for the desired view (MyTokenObtainPairView) and a subclass for its corresponding serializer (MyTokenObtainPairSerializer), add the following to the serializerclass MyTokenObtainPairSerializer(TokenObtainPairSerializer): ... @classmethod def get_token(cls, user): token = super().get_token(user) # Add custom claims token['iat'] = datetime.datetime.now() token['user'] = user.username token['date'] = str(datetime.date.today()) return token然后,当您发布到同一位置时,您将获得像这样的访问令牌Then, when you POST to that same location, you'll get an access token like thiseyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTkwOTE0MTk4LCJqdGkiOiJhZDZmNzZhZjFmOGU0ZWJlOGI2Y2Y5YjQ4MGQzZjY2MiIsInVzZXJfaWQiOjExLCJpYXQiOjE1OTA5MTc0OTgsInVzZXIiOiJ0aWFnbyIsImRhdGUiOiIyMDIwLTA1LTMxIn0.-5U9P-WWmhlOenzCvc6b7_71Tz17LyNxe_DOMwwqH4RqrNsilVukEcZWFRGupLHRZjIvPya2QJGpiju9ujzQuw使用JWT,您可以看到有效负载发生了相应的变化Using JWT you can see the Payload changing accordingly{ "token_type": "access", "exp": 1590914198, "jti": "ad6f76af1f8e4ebe8b6cf9b480d3f662", "user_id": 11, "iat": 1590917498, "user": "tiago", "date": "2020-05-31"} 这篇关于向DRF简单JWT有效负载添加声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!