python flask log 2 POST GET
from flask import Flask,render_template,url_for,redirect, request
app=Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/second')
def test():
return render_template('test.html')
@app.route('/third')
def testThird():
return redirect(url_for('index'))
@app.route('/postExample',methods=['POST','GET'])
def postExample():
if request.method == 'POST':
if request.values['send']== '送出':
return render_template('postExample.html',name=request.values['user'])
return render_template('postExample.html',name="")
if __name__ == '__main__':
app.run(host='0.0.0.0',port='5000',debug=True)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ironman Day4</title>
</head>
<body>
{% if name == "" %}
<form method="post">
<input type="text" name="user">
<input type="submit" name="send" value="送出">
</form>
{% else %}
<p>Hello,{{name}}</p>
{% endif %}
</body>
</html>
留言
張貼留言