我正在使用模型来保存用户信息,例如个人资料图片和个人简介等,但是当我注册时会发生此错误。 这是代码
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete='CASCADE')
description = models.CharField(max_length = 500, default='', blank = True)
city = models.CharField(max_length = 100, default='', blank = True)
website = models.URLField(default='', blank = True)
phone = models.IntegerField(default='', blank = True)
image = models.FileField()
@receiver(post_save, sender = User)
def create_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
instance.userprofile.save()
最佳答案
invalid literal for int() with base 10: ''
表示不能做Type Conversion
上''
.
我想phone = models.IntegerField(default='', blank = True)
这是问题所在。
因为你没有给 phone
赋值,所以它使用默认值 ''
,不能通过 int()
进行转换在Python中。
关于python - 异常: invalid literal for int() with base 10: '' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50834317/