目錄
-
請求
-
響應
# 使用return直接響應字符串 @app.route('/') def index(): return 'Hello Flask!' return 'Hello Flask!',404 #響應內容並響應狀態碼 通過make_response構造響應 導入: from flask import make_reponse @app.route('/') def index(): return make_response('Hello Flask!') return make_response('Hello Flask!',404) #響應內容並響應狀態碼
-
消息閃爍
# 配置 app.config["SECRET_KEY"] = "qieqw0923-0-klzd//../op[p%^]" # 使用 在需要彈出消息時,使用 flash 函數保存閃爍消息 @app.route('/') def index(): flash('hello') return render_template('index.html')
# 在模板文件中顯示閃爍消息時,可以通過函數 get_flashed_messages 獲取 # 從bootstrap上粘貼1個可消失的警告框 {% for message in get_flashed_messages() %} <div class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" arialabel="Close"><span aria-hidden="true">×</span> </button> {{ message }} </div> {% endfor %}