使用关闭按钮在 DJango 中显示 Flash 消息

doe*_*uvc 5 python django web2py django-views flash-message

我想使用关闭按钮在 Django 中显示 Flash 消息。Django 中现有的消息框架允许显示消息但不允许关闭它。

例如,web2py 提供了这样的 flash 消息。我正在 Django 中寻找类似的功能。

web2py 中的 Flash 消息

如果可以用几行代码完成,那就太好了。我不想在 Django 之上添加任何其他库或框架。

提前致谢。

doe*_*uvc 9

我不知道这样的事情可以使用 boot-strap 解决!

我做了这样的事情:

{% if messages %}
  {% for msg in messages %}
    <div class="alert alert-info alert-dismissable">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
      {{msg.message}}
    </div>
  {% endfor %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)

它显示如下消息: Django 中的 Flash 消息