我有一个CreateView,我希望它被调用并填充初始数据:
class StartGame(PermissionRequiredMixin, CreateView):
model = Author
fields = {'date_of_death'}
permission_required = 'catalog.can_mark_returned'
def get_initial(self):
# Get the initial dictionary from the superclass method
initial = super(StartGame, self).get_initial()
# Copy the dictionary so we don't accidentally change a mutable dict
initial = initial.copy()
initial['card'] = '0'
print(initial)
initial['bb'] = '0'
print(initial)
return initial
但是当我从urls.py调用它时,它只能作为。我尝试以不同的方式填充'card':'0',“ 0”,0-都一样:
模型看起来是这样
class Author(models.Model):
"""Model representing an author."""
card = models.CharField(max_length=100)
second_card = models.CharField(max_length=100)
date_of_birth = models.DateField(null=True, blank=True)
date_of_death = models.DateField('died', null=True, blank=True)
bb = models.IntegerField(default=0)
voted_id = models.CharField(max_length=1000,default="zero")
我只是不明白为什么它不起作用