django rest-auth 获取用户配置文件

django rest-auth get user profile

我有点迷茫...我正在尝试开发一个离子应用程序 需要针对 Django 网络应用程序进行身份验证。

我安装了 Django-Rest-Framework 和 Django-Rest-Auth。我能够登录,使用令牌获取用户,但如何检索更多用户数据?

url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-token-auth/$',obtain_auth_token),

在主机中使用 Django-rest-auth。com/rest-auth/user/ url 我只有这些数据:

HTTP 200 OK
Content-Type: application/json
Vary: Accept
Allow: GET, PUT, HEAD, OPTIONS, PATCH

{
    "username": "ikerib",
    "email": "ikerib@gmail.com",
    "first_name": null,
    "last_name": null
}

但我需要更多!像 id,user_photo,城市...

我试过像这样配置用户序列化程序:

from rest_framework import serializers
from gamer.models import GamerUser

class GameUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = GamerUser
        fields = ('id', 'fullname', 'get_photo', 'karma')

和这个观点:

@csrf_exempt
def gameuser_detail(request, pk):
    try:
        gameuser = GameUser.objects.get(pk=pk)
    except GameUser.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = GameUserSerializer(gameuser)
        return JSONResponse(serializer.data)

但我无法获取用户数据,因为我不知道用户 ID..

任何帮助或线索???

提前致谢

您只需将自定义序列化程序添加到您的应用设置中,如下所示:

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'path.to.custom.GameUserSerializer',
}

http://django-rest-auth.readthedocs.org/en/latest/configuration.html