flask中flash消息框的自动(定时)隐藏

BEGIN:

花了较长时间整出来这个可用的使flask消息框自己消失的方法,需要的拿走。js很简单,却搞了很久,唉~

ps:这里是渐变式的消失效果。

view.py

@frontend.route(’/logout’)
@login_required
def logout():
logout_user()
flash(‘登出成功’,‘success’)
return redirect(url_for(‘frontend.index’))
html

flash中有两个参数:messages和category,其中 category作为信息标记列表,用于区分信息的类型,messages里存放消息列表,在html中对其进行遍历取得各个fash信息,这里新增div元素,使消息显示出来。

复制代码
{% block flash_message %}


{% with messages = get_flashed_messages(with_categories=True) %}
{% if messages %}


{% for category, msg in messages %}

×
{{ msg }}

{% endfor %}


{% endif %}
{% endwith %}

{% endblock %}
复制代码

js

这里通过classname取得消息框的div元素,定时1.5秒,使其在1.5秒内渐渐消失。

END.

扫描二维码关注公众号,回复: 11625174 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_41299338/article/details/108469023