*.问题记录集1

来源:互联网 发布:php实例教程 编辑:程序博客网 时间:2024/05/01 18:49
  • 代码错误

错误

django model 中代码如下

from django.db import modelsfrom django.contrib.auth.models import User# Create your models here.class UserProfile(models.Model):    user = models.ForeignKey(to=User, related_name="user_manager")    ARTICLE_CHOICES = {        ("normal", "normal"),        ("author", "author"),    }    role = models.CharField(choices=ARTICLE_CHOICES, max_length=20)    email = models.CharField(max_length=50)    def __str__(self):        return str(self.id)

api.view 代码如下:

class UserSerializer(serializers.ModelSerializer):    class Meta:        model = User        fields = ('id', 'username')@api_view(['GET', 'POST'])@authentication_classes((TokenAuthentication,))def users(request):    users_list = UserProfile.objects.filter()    serializer = UserSerializer(users_list, many=True)    return Response(serializer.data)

总是报username 错误
纠结了一个多小时,后来发现 user_list UserProfile 没有改成User ,导致一直报错。

  • password 序列化问题
    序列化取出后为加密后的,修改passwod 是否需要序列化取出??
  • 附加序列化
    http://www.django-rest-framework.org/api-guide/relations/
原创粉丝点击