Python 无法在Django中生成表单
我最近开始为我的一个个人项目制作Django web应用程序。我制作了一个模型,Python 无法在Django中生成表单,python,django,Python,Django,我最近开始为我的一个个人项目制作Django web应用程序。我制作了一个模型,makemigrations/migrate工作正常。当我创建表单并运行这些命令时,我收到以下错误:django.core.exceptions.FieldError:为工作表指定的未知字段(mideals) forms.py from django import forms from . import models class CreateSheet(forms.ModelForm): class Met
makemigrations
/migrate
工作正常。当我创建表单并运行这些命令时,我收到以下错误:django.core.exceptions.FieldError:为工作表指定的未知字段(mideals)
forms.py
from django import forms
from . import models
class CreateSheet(forms.ModelForm):
class Meta:
model = models.Sheet
fields = [
'name', 'slug', 'Class', 'background', 'race', 'xp', 'level',
'strength', 'dexterity', 'constitution', 'intelligence', 'wisdom',
'charisma', 'strengthMod', 'dexterityMod', 'constitutionMod',
'intelligenceMod', 'wisdomMod', 'charismaMod', 'sStrength',
'sDexterity', 'sConstitution', 'sIntelligence', 'sWisdom',
'sCharisma', 'acrobatics', 'animalHandling', 'arcana', 'athletics',
'deception', 'history', 'insight', 'intimidation', 'investigation',
'medicine', 'nature', 'perception', 'performance', 'persuasion',
'religion', 'sleightOfHand', 'stealth', 'survival',
'acrobaticsMod', 'animalHandlingMod', 'arcanaMod', 'deceptionMod',
'historyMod', 'insightMod', 'intimidationMod', 'investigationMod',
'medicineMod', 'natureMod', 'perceptionMod', 'performanceMod',
'persuasionMod', 'religionMod', 'sleightOfHandMod', 'stealthMod',
'survivalMod', 'otherProficiencies', 'languages', 'equipment',
'copper', 'silver', 'gold', 'platinum', 'armorClass', 'initiative',
'speed', 'maxHitPoints', 'hitPoints', 'hitDice', 'sDeathSave1',
'sDeathSave2', 'sDeathSave3', 'fDeathSave1', 'fDeathSave2',
'fDeathSave3', 'personalityTraits', 'mideals', 'bonds', 'flaws',
'featuresTraits',
]
models.py
from django.db import models
# Create your models here.
class Sheet(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField(default="")
Class = models.CharField(max_length=100)
background = models.CharField(max_length=100)
race = models.CharField(max_length=100)
xp = models.IntegerField()
level = models.IntegerField()
strength = models.IntegerField()
dexterity = models.IntegerField()
constitution = models.IntegerField()
intelligence = models.IntegerField()
wisdom = models.IntegerField()
charisma = models.IntegerField()
strengthMod = models.IntegerField()
dexterityMod = models.IntegerField()
constitutionMod = models.IntegerField()
intelligenceMod = models.IntegerField()
wisdomMod = models.IntegerField()
charismaMod = models.IntegerField()
sStrength = models.BooleanField()
sDexterity = models.BooleanField()
sConstitution = models.BooleanField()
sIntelligence = models.BooleanField()
sWisdom = models.BooleanField()
sCharisma = models.BooleanField()
acrobatics = models.BooleanField()
animalHandling = models.BooleanField()
arcana = models.BooleanField()
athletics = models.BooleanField()
deception = models.BooleanField()
history = models.BooleanField()
insight = models.BooleanField()
intimidation = models.BooleanField()
investigation = models.BooleanField()
medicine = models.BooleanField()
nature = models.BooleanField()
perception = models.BooleanField()
performance = models.BooleanField()
persuasion = models.BooleanField()
religion = models.BooleanField()
sleightOfHand = models.BooleanField()
stealth = models.BooleanField()
survival = models.BooleanField()
acrobaticsMod = models.IntegerField()
animalHandlingMod = models.IntegerField()
arcanaMod = models.IntegerField()
deceptionMod = models.IntegerField()
historyMod = models.IntegerField()
insightMod = models.IntegerField()
intimidationMod = models.IntegerField()
investigationMod = models.IntegerField()
medicineMod = models.IntegerField()
natureMod = models.IntegerField()
perceptionMod = models.IntegerField()
performanceMod = models.IntegerField()
persuasionMod = models.IntegerField()
religionMod = models.IntegerField()
sleightOfHandMod = models.IntegerField()
stealthMod = models.IntegerField()
survivalMod = models.IntegerField()
otherProficiencies = models.CharField(max_length=250)
languages = models.CharField(max_length=250)
equipment = models.CharField(max_length=250)
copper = models.IntegerField()
silver = models.IntegerField()
gold = models.IntegerField()
platinum = models.IntegerField()
armorClass = models.IntegerField()
initiative = models.IntegerField()
speed = models.IntegerField()
maxHitPoints = models.IntegerField()
hitPoints = models.IntegerField()
hitDice = models.CharField(max_length=250)
sDeathSave1 = models.BooleanField(default=False)
sDeathSave2 = models.BooleanField(default=False)
sDeathSave3 = models.BooleanField(default=False)
fDeathSave1 = models.BooleanField(default=False)
fDeathSave2 = models.BooleanField(default=False)
fDeathSave3 = models.BooleanField(default=False)
personalityTraits = models.CharField(max_length=250)
ideals = models.CharField(max_length=250)
bonds = models.CharField(max_length=250)
flaws = models.CharField(max_length=250)
featuresTraits = models.CharField(max_length=250)
def __str__(self):
return self.name
我真的不知道这里发生了什么。我已经查看了堆栈溢出,似乎与我的错误几乎没有任何关系。任何帮助都将不胜感激。您指定希望表单中包含字段
mideals
,但该字段在工作表
模型中不存在。您应该从表单上的字段列表中删除该字段,或者将其添加到模型中
如果希望模型中的所有字段都显示在表单上,最好使用
fields='\uuuu all\uuuu'
错误非常清楚,您指定了一个不在模型中的字段mideals
。看起来它可能是理想的打字错误?。(但是,神圣的****,拥有一个包含这么多字段的模型,然后在表单中按名称单独包含它们是很痛苦的。至少要使用简写。或者如果有一些您不想要的,请使用排除)。老实说,这是我见过的最长的模型:D。。无论如何,这只是因为您的模型没有字段名,而您将字段名放在表单的fields属性中-mideals
。如果您的模型没有该字段,请删除它;如果您认为确实需要它,请将其添加到您的模型中。谢谢!这修复了它,而且我也不知道所有的速记,这是非常有用的。