Python django表单字段没有值抛出不能为空错误
详细代码: 表格: 观点:Python django表单字段没有值抛出不能为空错误,python,django,forms,Python,Django,Forms,详细代码: 表格: 观点: def exp_manage(request, exp_type, id=None): if id: exp = Experience.objects.get(id=id) else: exp = None ExpForm = get_exp_form(exp_type) if request.method == 'POST': form = ExpForm(request.POST,
def exp_manage(request, exp_type, id=None):
if id:
exp = Experience.objects.get(id=id)
else:
exp = None
ExpForm = get_exp_form(exp_type)
if request.method == 'POST':
form = ExpForm(request.POST, instance=exp)
if form.is_valid():
return http.HttpResponseRedirect(reverse('zhemei_resume_manage'))
else:
form = ExpForm(instance=exp)
我在第行设置了一个断点:如果form.is\u valid():
>>> request.POST.get('exp_type')
u'T'
>>> form.data.get('exp_type')
u'T'
>>> form.errors
{'exp_type': [u'can not be null']}
我不明白上面的结果是什么。我还试图弄清楚django表单
如何生成form.errors
。但是我在django源代码中找不到相关代码。任何人都可以帮助?清除xxx方法字段的返回值:
def clean_exp_type(self):
exp_type = self.cleaned_data.get('exp_type')
if not exp_type:
exp_type = self.initial['exp_type']
return exp_type
你太棒了!我忘了,我试着设置self.cleaned_data['exp_type'],这让我痛苦了几个小时。非常感谢。
def clean_exp_type(self):
exp_type = self.cleaned_data.get('exp_type')
if not exp_type:
exp_type = self.initial['exp_type']
return exp_type