gpt4 book ai didi

python - 异常: invalid literal for int() with base 10: ''

转载 作者:行者123 更新时间:2023-12-01 09:20:26 25 4
gpt4 key购买 nike

我正在使用模型来保存用户信息,例如个人资料图片和个人简介等,但是当我注册时会发生此错误。这是代码

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com