如何在django的消息中添加boostrap



我创建了一个表单,如果表单有任何来自用户的错误,我在模板中添加一个django消息。它工作,但它只显示文本。我想把它突出显示为错误信息,但我不知道如何在消息中添加boostrap

我不知道该怎么做。

您可以像往常一样将消息放入boostrap类中。

<dev class="alert alert-warning" role="alert">
{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %}

Django在Web页面显示Bootstrap消息

步骤:

# 1 - Add Code in (setting.py)

from django.contrib.messages import constants as messages

MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}

# 2 - Add Code in (html.page) for message display

{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{{ message }}
</div>
{% endfor %}

最新更新