前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python flask flash消息

python flask flash消息

作者头像
py3study
发布2020-01-06 20:19:30
8820
发布2020-01-06 20:19:30
举报
文章被收录于专栏:python3

flash 消息闪现

很多人都不用flash这个组件,其实特别好用。 好的应用和用户界面的重点是回馈。如果用户没有得到足够的反馈,他们可能最终会对您的应用产生不好的评价。Flask 提供了一个非常简单的方法来使用闪现系统向用户反馈信息。闪现系统使得在一个请求结束的时候记录一个信息,然后在且仅仅在下一个请求中访问这个数据。这通常配合一个布局模板实现。

具体请查看: http://docs.jinkan.org/docs/flask/patterns/flashing.html

标准的bootstrap

template html

利用bootstrap的类的方法名来做这类的事情 success : 为绿色的 danger : 为红色的 warning : 为×××的

/templates/flash.html

代码语言:javascript
复制
<body class="gray-bg">
<!--通知消息处-->
    {% with messages = get_flashed_messages(with_categories=true) %}
      {% if messages %}
        {% for category, message in messages %}
            <div class="alert alert-{{ category }}" style="text-align: center">
            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
            <strong>{{ message }}</strong></div>
        {% endfor %}
      {% endif %}
    {% endwith %}
</body>

controller action

下一个访问请求之中获取这个数据 /main.py

代码语言:javascript
复制
app.route("flash")
def view_flash()
    flash(message, action)
    action = ["success", 'error', 'danger'] ...
    return render_template("flash.html")
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • flash 消息闪现
    • 标准的bootstrap
      • template html
    • controller action
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档