1, get request.
Usage scenarios: access to information does not modify the data or resource server, use get.
Parameter passing: "?" Get request to pass parameters is in the URL, in the form specified by pairs.
2, post request.
Usage scenarios: an impact on the server, with the post.
Biography Reference: post is not in the URL, but send "form data" in the form to the server.
3, use:
app.route @ ( ' / ' ) DEF the hello_world (): return the render_template ( ' index.html ' ) @ app.route ( ' / Search / ' ) DEF Search (): return ' ! Search ' corresponding to the index page of: <a href= "{{ url_for(" search " ,q =" hello ") }}"> Search keyword hello </a>
4, get get request keywords.
app.route @ ( ' / ' ) DEF hello_world (): return render_template ( ' index.html ' ) # Get keyword submitted by the user @ app.route ( ' / Search / ' ) DEF Search (): haha = Request. . args GET ( ' Q ' ) Print (haha) return ' key submitted by the user is: S% ' % haha
<a the href = " {{the url_for ( " Search " , Q = " Hello ") }}"> Search </a>
5, submit and obtain post request keywords.
G:\Flask\get_post\app.py
# post请求与获取提交的关键字
@app.route('/login/',methods=["POST","GET"])
def login():
if request.method == "GET":
return render_template('login.html')
else:
username = request.form.get('username')
password = request.form.get('password')
return "username:%s /n password:%s" %(username,password)
login.html
<form action="{{ url_for('login') }}" method="post">
<input type="text" name="username" placeholder="请输入用户名"><br>
<input type="password" name="password" placeholder="请输入密码"><br>
<input type="submit" name="username" value="登录">
</form>