在我用django提交一个有错误的表单之后,表单的所有字段都将被清除。我想保留字段上的信息,因为它将帮助用户提交数据。在
这是我的视图.py应用程序:
def new(request):
context = {}
if request.method == 'POST':
form = NewSubject(request.POST)
if form.is_valid():
context['is_valid'] = True
form.save()
form = NewSubject()
else:
context['is_valid'] = False
else:
form = NewSubject()
context['form'] = form
return render(request, 'subjects/new.html', context)
就像bearbrown所说的,数据在出错后仍然保留在字段上,但是我怎么没有使用Django的纯表单,我需要做一些调整。 我用原始的Django表单创建了一个隐藏的div,并使用JavaScript传递字段的数据。 这是我如何继续的一个例子:
^{pr2}$谢谢你的帮助!在
我建议您使用ajax,因为这样我们可以编写不同的案例来处理提交是否成功。如果成功输入值.val('')其他 显示错误和未清除输入字段。在
相关问题 更多 >
编程相关推荐