我收到以下错误
ValidationError:ValidationError(值必须是['AL','CT','DE','FL'......'WY']之一:['state'])
但是当我在我的模型中时,我似乎无法弄清楚为什么它会验证该字段;
class User(mongoengine.Document):
username = mongoengine.StringField(unique=True, max_length=30, required=True,verbose_name="Pick a Username")
state = mongoengine.ListField(required=False, verbose_name="State", choices=[('AL' , 'Alabama'), ('AK' , 'Alaska') ,('AZ' , 'Arizona'), ('AR' , 'Arkansas') ,('CA' , 'California'), ('CO' , 'Colorado') ,('CT' , 'Connecticut'), ('DE' , 'Delaware') ,('FL' , 'Florida')...('WY' , 'Wyoming')])
user_form = model_form(User, exclude=['password','name','address','address2','zipcode','state'])
signup_form = model_form(User, exclude=['name','address','address2','zipcode','state'])
我很茫然,因为我虽然起初 require=false 意味着它会被忽略,其次 exclude 也让我认为它应该被忽略。为什么这个验证错误仍然发生(除了我没有在表格中填写它的事实)?有关更多上下文,可以在此处找到完整的 model.py 和 app.py
https://github.com/markbreneman/TroubleShooting/tree/master/SecondNatureWebsite