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

Python+Flaskで、セッション(session)

$
0
0
Python+Flaskで、セッション(session)です。app.secret_keyを設定しないと、500番のエラーになります。


The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
from flask import Flask, session, escape

app = Flask(__name__)

@app.route('/')
session['username'] = 'aaa'
username = escape(session['username'])
return render_template('index.html', username=username)

app.secret_key = 'abcdefg123456'

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

参考サイト
Quickstart(Flask Documentation)

Viewing all articles
Browse latest Browse all 846

Trending Articles