django rest api FieldError:无法将关键字“i”解析为字段

时间:2017-03-20 19:42:29

标签: python django rest api

我在django中面临这个奇怪的问题“FieldError:无法将关键字'i'解析为字段”。我想要找到问题一小时。下面是我的模特

from django.db import models

# Create your models here.
def code_generate():
    while 1:
        from django.conf import settings
        import random, string
        code = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6))
        try:
            Users.objects.get(id=code)
        except:
            return code

class Users(models.Model):
    class Meta:
        db_table='users'
    id = models.CharField(primary_key=True, default=code_generate, max_length=100)
    name = models.CharField(max_length=50)
    username = models.CharField(max_length=50, unique=True)
    password = models.CharField(max_length=100)
    creation_timestamp = models.DateTimeField(auto_now=True)
    email = models.EmailField(max_length=150)
    mobile = models.CharField(max_length=25)

class Login(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=100)

我在调用serializer.is_valid

时收到此错误
  

“选择是:%s”%(名称,“,”。join(可用)))   django.core.exceptions.FieldError:无法将关键字“i”解析为字段。选择   s是:creation_timestamp,email,id,mobile,name,password,username

0 个答案:

没有答案