Flaskで以下のようなプログラムを組んでいます。
python
1import threading,webbrowser 2from flask import Flask, render_template, redirect, request 3from ext_py.dbshow import DB_show 4 5app = Flask(__name__) 6 7@app.route('/') 8def menu(): 9 return render_template('myapp/home.html', title='FLASK Menu') 10 11@app.route('/alldata') 12def alldata(): 13 dbs = DB_show() 14 dbinfos = dbs.selectall() 15 return render_template('myapp/alldata.html', title='alldata', alldata=dbinfos) 16 17@app.route('/browse/<string:pk>') 18def browse( pk ): 19 .... 20 何らかの処理 21 .... 22 return redirect('/alldata') 23 24if __name__ == "__main__": 25 threading.Timer(1.0, lambda: webbrowser.open('http://localhost:5000') ).start() 26 app.run(debug=False)
データベースからデータを読み込んで、alldata.htmlでテーブルに表示して、どれかの行をクリックすると pk が browse に送られて処理したあとに、もう一度 alldata に戻ると webページがどんどん追加されてしまいます。
新規画面がどんどん増えないようにしたいのですが、どうしたらいいのでしょうか?
もっと具体的に言うと、
- Flask のメソッドは必ず return を必要とするものなのでしょうか?
- 処理を済ませた後で前の画面に戻るということはできるのでしょうか?
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。