1 回答
TA贡献1865条经验 获得超7个赞
您需要将错误标签添加到模板中才能查看验证错误:
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger">
<strong>{{ error }}</strong>
</div>
{% endfor %}
{% endfor %}
{% for error in form.non_field_errors %}
<div class="alert alert-danger">
<strong>{{ error }}</strong>
</div>
{% endfor %}
{% endif %}
您还需要确保呈现原始完成的表单,以便显示错误。
def register(request):
if request.method == 'GET':
form = formss.Forms()
if request.method == 'POST':
form = formss.Forms(request.POST)
if form.is_valid():
form.save(commit=True)
return index(request)
return render (request , 'forms.html', context = {'form':form} )
添加回答
举报