我有一个自定义表单,每当我获取要保存在数据库中的表单值时,它就会显示一个错误(applicationform()获得了意外的关键字参数“job_title”),并且这些值不会保存在表中。在
在视图.py:-
def applicationvalue(request):
if request.method == 'POST':
getjobtitle = request.POST['jobtitle']
getintable = applicationform(job_title=getjobtitle)
getintable.save()
print getjobtitle
return HttpResponse(getintable)
else:
return render_to_response('registration/applicationform.html')
我的表格是:
^{pr2}$每当我从表单获取值以将值保存在表字段“job_title”中时,它将显示一个错误:
applicationform()获得意外的关键字参数“job\u title”
将html中的
input
字段名更改为job_title
然后在视图中做
^{pr2}$如果您使用相同的表单来呈现html而不是手工编码它,这会更好。在
applicationform
构造函数应将request.POST
作为参数。 但在我看来,你没有以“正确”的方式使用django表单。我认为你的观点不符合django使用形式的哲学。在在您的情况下,您应该有一个模型:
基于此模型,可以声明一个ModelForm:
^{pr2}$然后您可以在视图中使用此窗体
最后,您应该有一个
registration/applicationform.html
模板,它类似于:我希望有帮助
相关问题 更多 >
编程相关推荐