やりたい事
- flaskのルーティングで共通の処理を実行したい。
- 例えば、ログイン後のセッションチェック等
コードについて
- ルーティングはBlueprintで分割しています。
- 全ルーティング共通となると、indexページでもセッションチェックが入ってしまうため、Blueprint毎等、適宜設定できると嬉しいです。
- 現在は、各ルーティング関数内で共通関数を呼び出している状態ですが、下記のコードのようにおまじない的な感じになる為できたら辞めたいと思っています。
一部抜粋:
python
1@app.route("/top") 2def top(): 3 if sessionCheck(): 4 return redirect(url_for('index.index')) 5 6 # 各種処理 7 8 return render_template('top.html') 9 10@app.route("/search") 11def search(): 12 if sessionCheck(): 13 return redirect(url_for('index.index')) 14 15 # 各種処理 16 17 return render_template('search.html')
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。