python - 例外:int() 以 10 为底的无效文字:''
问题描述
我正在使用模型来保存个人资料图片和简历等用户信息,但是当我注册时会发生此错误。这是代码
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()
解决方案
基数为 10 的 int() 的无效文字:''
意思是不能做Type Conversion
对''
。
我想phone = models.IntegerField(default='', blank = True)
是这个问题。
因为你没有给 赋值phone
,所以它使用默认值,在python''
中无法转换。int()