multiple modelforms errors
views.py
def fadded(request): if request.method == "POST": fform = FtForm(request.POST) bform = BgForm(request.POST) if fform.is_valid() and bform.is_valid(): bcontent=bform.save() fcontent=fform.save() else: return render_to_response("ft.html", { "fform": fform, "bform": bform, },context_instance=RequestContext(request)) return HttpResponse('OK!')
ft.html
... {% if form.errors%} {% for error in form.errors %} {{ error|escape }} {% endfor %} {% endif %} ...
There are two modelforms: fform and bform. They represent two different models, but are used in same template. I'm trying to save both and to get form-/fielderrors from both. But if there are already fform.errors, django doesn't shows bform.errors(and propably doesn't even create bform). Any proposals for a different way?
django doesn't shows bform.errors(and propably doesn't even create bform)
Given your setup, both forms are passed data and are ready to be validated. There shouldn't be a problem.
In your template, you'd have to display both forms errors (I only see one form being checked in your template)
{{ fform.errors }} <!-- show errors from fform -->
{{ bform.errors }} <!-- show errors from bform -->
链接地址: http://www.djcxy.com/p/9668.html
上一篇: 保存表单数据会重写同一行
下一篇: 多个模型错误