如何呈现不在 UL 中的 Django 表单错误? [英] How to render Django form errors not in a UL?
本文介绍了如何呈现不在 UL 中的 Django 表单错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 Django 表单中的错误按照 docs 在 UL 中呈现...
The errors in my Django form are rendering in a UL as per the docs...
姜戈
{{ form.non_field_errors }}
HTML
<ul class="errorlist">
<li>Sender is required.</li>
</ul>
如何呈现错误,使它们不出现在 UL 中,而是出现在每个字段相关错误的段落标记中?所以理想...
How can I render the errors so they appear not in a UL, but in a paragraph tag for each fields relevant error? So ideally...
<ul>
<li>
<label>...</label>
<input>...</input>
<p>Error message...</p>
</li>
</ul>
为了清楚起见,我应该在示例中使用此代码...
I should have used this code in my example for clarity...
{{ form.fieldname.errors }}
推荐答案
你可以在你的模板中显示你的错误如下:
You can display your error as the following in your template:
<p>{{ form.fieldname.errors.as_text }}</p>
这篇关于如何呈现不在 UL 中的 Django 表单错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文