简体   繁体   English

使用引导程序样式化错误消息

[英]Styling error messages with bootstrap

I'm building my own form to git rid of help text, As I can't change the builtin form in django to remove the help text. 我正在构建自己的表单来摆脱帮助文本,因为我无法更改django中的内置表单来删除帮助文本。

So far so good, but I can't style the error messages. 到目前为止,一切都很好,但是我无法设置错误消息的样式。

It's showing basic ul and il style. 它显示了基本的ul和il样式。

How can I do it ? 我该怎么做 ? Thanks. 谢谢。

<form class="" method="post">
   {% csrf_token %}
          <label for="id_new_password1"> Senha </label><br>
    <div class="">
        <input required text="password" class="form-control" placeholder="Senha" name="new_password1"/>
            {{ form.new_password1.errors }}
    </div><br>
         <label for="id_new_password2"> Confirmar senha </label><br>
    <div class="">

       <input required text="password" class="form-control" placeholder="Confirmar senha" name="new_password2"/>
        {{ form.new_password2.errors }}
    </div><br>
    <input type="submit" class="btn btn-primary col-sm-12" value="Confirmar" />

</form>

You can use alerts . 您可以使用警报 Like this: 像这样:

{% if form.new_password1.errors %}
    <div class="alert alert-danger" role="alert">{{ form.new_password1.errors }}</div>
{% endif %}

Also, have you tried this answer trying to get rid of the help_text? 此外,您是否尝试过此答案以摆脱help_text?

Try to wrap up error messages in one element. 尝试将错误消息包装在一个元素中。

<div class="error-messages">{{ form.new_password1.errors }}</div>

.error-messages {
  color: red;
  font-size: 12px; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM