So I am using Django Rest framework for my APIs and was trying to create an API for the auth user model. Here is my Serializer class
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
exclude = ('password',)
My View class is as follows
class UserApiDetailView(RetrieveAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
and my url for the same is as follows
url(r'^user/(?P<pk>[0-9]+)/$', views.UserApiDetailView.as_view()),
I am getting the following output on calling the API
HTTP/1.0 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Date: Sat, 12 Dec 2015 18:54:04 GMT
Server: WSGIServer/0.1 Python/2.7.10
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN
{
"date_joined": "2015-10-30T06:25:17.400955Z",
"email": "<UITextField: 0x7fee18f6fa10",
"first_name": "",
"groups": [],
"id": 2,
"is_active": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
"last_name": "",
"user_permissions": [],
"username": "<UITextField: 0x7fee18f69ad0"
}
Instead of getting the actual value for username and email, I'm getting UITextField: 0x7fee18f69ad0.
Am I missing something ?
Also, When I use ListAPIView, Everything gets works perfectly.
I have a theory. This is probably what's happening:
UITextField
object, serialized as string, instead of it's value. Debugging The issue:
Check the username
and password
field for that particular user in django admin or even better in database. That will help you find what's really in database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.