I use django-rest-auth
in my Django project.
After login the rest-auth/login/
, how to return more information?
In the rest-auth/login/
, when I login the user, it returns a key
.
I want to also return the user’s information, how can I get this?
Advertisement
Answer
At last, I get my solution:
class TokenSerializer(serializers.ModelSerializer): """ Serializer for Token model. """ user = UserInfoSerializer(many=False, read_only=True) # this is add by myself. class Meta: model = TokenModel fields = ('key', 'user') # there I add the `user` field ( this is my need data ).
In the project settings.py
, add the TOKEN_SERIALIZER
like bellow:
REST_AUTH_SERIALIZERS = { ... 'TOKEN_SERIALIZER': 'Project.path.to.TokenSerializer', }
Now I get my need data: