码迷,mamicode.com
首页 > 其他好文 > 详细

Flask -- 消息闪现、错误处理

时间:2016-04-27 22:38:21      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:


 flash 可以在任何需要的地方添加,类似于print

from flask import flash


@app.route(/)
def index():
    flash(You are in home page now)
    return render_template(index.html)
#index.html


{% for message in get_flashed_messages() %}    # 和session一样, 可以在模板中直接使用

    {{ message }}

{% endfor %}

自定义错误页面

@app.errorhandler(404)
def page_not_found(error):
    try:
        return render_template(404.html)
    except Exception as e:
        return render_template(500.html, error=e)

 

Flask -- 消息闪现、错误处理

标签:

原文地址:http://www.cnblogs.com/roronoa-sqd/p/5440561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!