formを受け取る側はmethodsを指定する必要あり
from flask import Flask, render_template, request app = Flask(__name__) @app.route('/form') def form(name=None): return render_template('post.html') @app.route('/hello', methods=["POST"]) def hello(): if request.method == 'POST': name = request.form['name'] else: name = 'no name.' return render_template('hello.html', title='flask test', name=name) if __name__ == "__main__": app.run(debug=True, host='192.168.56.10', port=8000)
queryをgetで取得する場合
=> request.args.getで取得する
http://192.168.56.10:8000/hello?name=yoko
from flask import Flask, render_template, request app = Flask(__name__) @app.route('/hello') def hello(): name = request.args.get('name') return render_template('hello.html', title='flask test', name=name) if __name__ == "__main__": app.run(debug=True, host='192.168.56.10', port=8000)