hand
_1_1_14
4
python3.X - Web - Flask1.1.1
共46篇
python3.X - Web - Flask1.1.1
返回栏目
0k
0.3k
1k
6k
0.6k
0.8k
0.3k
0.1k
0.2k
0.8k
0.6k
0.6k
0.1k
0.5k
0.2k
2k
0.3k
5k
2k
2k
1k
0.3k
1k
0.1k
1k
1k
0.5k
2k
2k
0.7k
1k
2k
0.1k
1k
0.1k
2k
2k
0.9k
5k
4k
1k
1k
3k
1k
0k
0k
返回python3.X - Web - Flask1.1.1栏目
作者:
贺及楼
成为作者
更新日期:2024-05-18 12:24:01
作用:http[GET][POST]获得参数
url:
域名.com/xx?value=4
value = request.args['value']
value = request.args.get('value')
json传输"":""
$.ajax({
url:"/",
type:'get',
dataType:"text",
data:{
x:{ 'id':'02' },
//发送的东西
},
success:function(data){
//成功之后
},
error:function(jqXHR){
alert("发生错误:"+ jqXHR.status);//错误
}
})
data = request.args['x']#获得数据
data1 = json.loads(data)#json读取
id = data1["id"]
name = data1["name"]
json传输"":""
$.ajax({
url:"/",
type:'post',
dataType:"text",
data:{
"title":"1",
//发送的东西
},
success:function(data){
//成功之后
},
error:function(jqXHR){
alert("发生错误:"+ jqXHR.status);//错误
}
})
#获得参数
value = request.json['value']
value = request.json.get('value')
# 接收body raw
{
"data":["a","b","c"]
}
import json
from flask import Flask, jsonify, request
@xxx.route("/xxx", methods=['POST'])
def xxx():
try:
data = request.data
data = json.loads(data)
doc = data['data']
print(doc)
return "ok"
except Exception as e:
print(e)
return "fail"
# 接收XML
#获得参数
data = request.data
print(data)
dict = xml_to_dict2(data)
# 处理返回预付单方法
def xml_to_dict2(data):
import xml.etree.ElementTree as ET
xml_dict = {}
data_dic = ET.fromstring(data)
for item in data_dic:
xml_dict[item.tag]=item.text
return xml_dict
print(request.__dict__) # 直接打印request
# 这是url
# xxx.com?xx=1&aa=2&bb=3
value1 = request.args['value']
value2 = request.args.get('value')
print("value1")
print(value1)
print("value2")
print(value2)
# 这是body的from-data形式有:KEY、VALUE、DESCRIPTION
value3 = request.json['value']
value4 = request.json.get('value')
print("value3")
print(value3)
print("value4")
print(value4)
# 这是body的raw的json形式
# {"AA":"aa","BB":"bb"}
value5 = request.from['value']
value6 = request.from.get('value')
print("value5")
print(value5)
print("value6")
print(value6)
data = request.args['x']#获得数据
data1 = json.loads(data)#json读取
id = data1["id"]
name = data1["name"]
print("1:request.form")
print(request.form)
print("2:request.data")
print(request.data)
print("3:request.method")
print(request.method)
print("4:request.values")
print(request.values)
print("5:request.headers")
print(request.headers)
print("6:request.args")
print(request.args)
print("7:request.json")
print(request.json)
python3.X - Web - Flask1.1.1
整章节共46节
快分享给你的小伙伴吧 ~