Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

Python+Flaskで、フラッシュメッセージ

$
0
0
Python+Flaskで、フラッシュメッセージです。

flash(u'(メッセージ)', '(カテゴリ)')

という具合に設定するらしい。

from flask import Flask, flash, redirect, render_template, request, url_for

app = Flask(__name__)

@app.route('/member')
def jump():
flash(u'ログインしてご利用ください。', 'info')
return redirect(url_for('login'))
テンプレートでの表示部分
{% with errors = get_flashed_messages(category_filter=["error"]) %}
{% if errors %}
{%- for msg in errors %}
{{ msg }}
{% endfor -%}
{% endif %}
{% endwith %}

実際に設定してみたのがこちら

参考サイト
Message Flashing(Flask Documentation)

Viewing all articles
Browse latest Browse all 846

Trending Articles