1.get请求
1.1概念
- 使用场景:如果只对服务器获取数据,并没有对服务器产生任何影响,这时候使用get请求
- 传参:get请求传参是放在url中,并且是以‘?’的形式来指定key和value的。
1.2使用
先来看一段代码。这是html。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<a href="{
{ url_for('search',q='hello') }}">跳转到搜索页面</a>
</body>
</html>
这是python
@app.route('/')
def index():
return render_template('index.html')
@app.route('/search/')
def search():
q = request.args.get('q')
return '用户提交的参数是%s' % q
在这里由首页跳转到搜索页面,并且在路径及传递一个参数q,value值为hello。请求的完整路径如下。