-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathdemo_api.py
83 lines (63 loc) · 1.93 KB
/
demo_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
# @Time : 2022/7/19 11:34
# @Author : ShaHeTop-Almighty-ares
# @Email : [email protected]
# @File : demo_api.py
# @Software: PyCharm
from flask import request
from all_reference import *
class MethodViewParams(MethodView):
"""
method view 获取get请求传参
"""
def get(self):
"""获取get请求传参"""
# 方法一:每个获取
a = request.args.get('a')
b = request.args.get('b')
print(a, b)
# 方法二:一次性或者再取值
data = request.args.to_dict()
print(data)
return api_result(code=200, message='MethodView获取get请求传参', data=data)
class MethodViewFormData(MethodView):
"""
method view 获取form-data传参
"""
def post(self):
"""获取form-data传参"""
# 方法一:每个获取
a = request.form.get('a')
b = request.form.get('b')
print(a, b)
# 方法二:一次性或者再取值
data = request.form.to_dict()
print(data)
a = data.get('a')
b = data.get('b')
print(a, b)
return api_result(code=200, message='MethodView获取form-data传参', data=data)
class MethodViewJson(MethodView):
"""
method view 获取JSON传参
"""
def post(self):
"""获取JSON传参"""
data = request.get_json()
d1 = data.get('d1')
d2 = data.get('d2')
d3 = data.get('d3')
print(d1)
print(d2)
print(d3)
return api_result(code=200, message='MethodView获取JSON传参', data=data)
class MethodViewBytesData(MethodView):
"""
method view 获取二进制data传参
"""
def post(self):
"""获取二进制data传参"""
data = request.get_data()
print(data)
print(type(data))
return api_result(code=200, message='MethodView获取二进制data传参', data=f"data is {type(data)}")