我收到此错误“'NoneType'对象没有属性'slug'”
在create_path的第48行中:return 'uploads/{0}/{1}'.format(instance.game.slug, filename)
model.py
def create_path(instance, filename):
return 'uploads/{0}/{1}'.format(instance.game.slug, filename)
class OnlineGame(models.Model):
name=models.CharField(max_length=120)
slug=models.CharField(max_length=25,unique=True)
icon=models.ImageField(upload_to='uploads/onlinegame',blank=True,null=True)
class Player(models.Model):
slug=models.SlugField(unique=True,max_length=120)
fullname=models.CharField(max_length=120,null=True,blank=True)
game=models.ForeignKey(OnlineGame,null=True,blank=True,related_name='playergame',on_delete=models.PROTECT)
答案 0 :(得分:0)
我忘记将slug=models.CharField(max_length=25,unique=True)
更改为slug=models.SlugField(max_length=25,unique=True)
现在可以了。