简体   繁体   English

django rest-auth获取用户个人资料

[英]django rest-auth get user profile

I´ma little bit lost... I´m trying to develop an ionic app witch needs to be authenticated versus Django web application. 我有点失落...我正在尝试开发一个离子应用程序,需要进行身份验证,而不是Django Web应用程序。

I installed Django-Rest-Framework and Django-Rest-Auth. 我安装了Django-Rest-Framework和Django-Rest-Auth。 I´m able to login, getin the user with the token, but how can I retrieve more User data? 我能够登录,使用令牌获取用户,但我如何检索更多用户数据?

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

With Django-rest-auth in host.com/rest-auth/user/ url I only have this data: 在host.com/rest-auth/user/ url中使用Django-rest-auth我只有这些数据:

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
}

But I need more! 但我需要更多! like id, user_photo, city... 像id,user_photo,city ...

I tried configuring a user serializer like this: 我尝试像这样配置用户序列化程序:

from rest_framework import serializers
from gamer.models import GamerUser

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

and this view: 而这个观点:

@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)

but I´m unable to get user data because I don´t know the user id.. 但我无法获取用户数据,因为我不知道用户ID ..

any help or clue??? 任何帮助或线索???

thanks in advance 提前致谢

You can simply add your custom serializer to your app settings like this: 您只需将自定义序列化程序添加到您的应用设置中,如下所示:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM