龙空技术网

get,post请求

PythoVie 404

前言:

眼前朋友们对“获取post请求的请求体”可能比较重视,兄弟们都需要学习一些“获取post请求的请求体”的相关资讯。那么小编同时在网上收集了一些对于“获取post请求的请求体””的相关内容,希望兄弟们能喜欢,各位老铁们一起来了解一下吧!

get请求:

1.使用场景:如果对服务器获取数据,并没有对服务器产生任何影响,贼使用get

2.传参:get请求传参是放在URL中,并通过‘?’形式指定key和value的

post请求:

1.使用场景:如果对服务器产生影响,那么使用post请求

2.传参:post请求传参不是放在URL中,是通过‘form data’的形式发送给服务器的

get和post请求获取参数:

1.get请求是通过‘flask.request.args’来获取

2.post请求是通过'flask.request.form'来获取

3.post请求在模板中要注意几点:

***input标签中,要写name来标识这个value的key,方便后台获取

***在写form表单的时候,要指定‘method=post’,并且要指定‘action‘/login/’’

示例代码:

<form action="{{ url_for('login') }}" method="post"><table><tbody><tr><td>用户名:</td><td><input type="text" placeholder="请输入用户名" name ="username"></td></tr><tr><td>密码:</td><td><input type="text" placeholder="请输入密码" name = "password"></td></tr><tr><td></td><td><input type="submit" value="登录"></td></tr></tbody></table></form>
@app.route('/')def index():return render_template('index.html')@app.route('/search/')def search():q = request.args.get('q')return u'用户提交的查询参数是:%s' %q#默认的视图函数,只能采用get请求#如果你想采用post请求,那么要写明...methods=['GET','POST']@app.route('/login/',methods=['GET','POST'])def login():if request.method == 'GET':return render_template('login.html')else:username = request.form.get('username')password = request.form.get('password')print('username:',username)print('password:',password)return 'success'

标签: #获取post请求的请求体