Django 页面加载时引导警报关闭
我在一个视图中发送了一些消息,如下所示:Django 页面加载时引导警报关闭,django,twitter-bootstrap,twitter-bootstrap-3,django-messages,Django,Twitter Bootstrap,Twitter Bootstrap 3,Django Messages,我在一个视图中发送了一些消息,如下所示: messages.warning(request, 'Nothing found") {% for message in messages %} <div class="alert {{ message.tags }} alert-dismissible fade in"> <button type="button" class="close" aria-label="Close">
messages.warning(request, 'Nothing found")
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible fade in">
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
{% if message.tags == 'info' %}
<p>{{ message }}<br>
You have <strong>{{users}}</strong> user{{users|pluralize}}<br>
,around <strong>{{non_users}}</strong> non user{{non_users|pluralize}}</p>
{% else %}
<p>{{ message }}</p>
{% endif %}
</div>
{% endfor %}
在mysettings.py
中,我编辑了如下消息标记:
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger'
}
在我的模板上,我按如下方式显示它们:
messages.warning(request, 'Nothing found")
{% for message in messages %}
<div class="alert {{ message.tags }} alert-dismissible fade in">
<button type="button" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
{% if message.tags == 'info' %}
<p>{{ message }}<br>
You have <strong>{{users}}</strong> user{{users|pluralize}}<br>
,around <strong>{{non_users}}</strong> non user{{non_users|pluralize}}</p>
{% else %}
<p>{{ message }}</p>
{% endif %}
</div>
{% endfor %}
{%用于消息中的消息%}
&时代;
{%if message.tags=='info%}
{{message}}
您有{{users}user{{{users|pluralize}}
,大约{{non_users}}非用户{{non_users}多元化}
{%else%}
{{message}}
{%endif%}
{%endfor%}
当加载模板时,消息会很快出现并消失
如果我尝试这样做:{{message}
相反,消息会留在那里,所以我猜我在引导方面出了问题
这(有点)也很有效:
有人能帮我照一下吗
编辑:
我只是注意到当我使用
消息时会发生这种情况。error()
,其余的消息工作正常,似乎找不到问题所在。试试这个,类是警报-{{tag}
,它将呈现警报信息
,没有空格
{% for message in messages %}
<div class="alert alert-{{message.tags}} page-alert">
<button type="button" class="close" data-dismiss='alert'>
<span aria-hidden="true"> × </span>
<span class="sr-only">Close</span>
</button>
<p>{{message}}</p>
</div>
{% endfor %}
{%用于消息中的消息%}
×
接近
{{message}}
{%endfor%}
单击“关闭”按钮时是否要销毁邮件?是的,它应该已经销毁了,但似乎警报类正在破坏某些内容。我的邮件标签已格式化为这样显示,到底是什么问题?似乎alert
类触发了关闭div的某个东西。我没有这样做的js代码。你是这样做的吗alert-alert-{{message.tags}}
而不是alert{{{message.tags}
?它应该像alert{{message.tags}}那样显示
翻译为警报