flask writing about the get, post of

 

One,

get method to get the reference method request.args.get

Address: 127.0.0.1:5000/test?arg1=1&arg2=2

Figure:

 

 

two,

The method of obtaining the pots more reference to method type, address 127.0.0.1:5000/test

1.request.get_json, into the reference format json { "arg1": 1, "arg2": "2"} FIG.

 

 

. 2.request form into the reference format, as:

 

 

 

code show as below:

 1 from flask import Flask
 2 app = Flask(__name__)
 3 
 4 @app.route('/xxxx',methods=['GET','POST'])
 5 def xxxx():
 6     if request.method == 'POST':
 7         #入参 json格式
 8         argsJson = request.get_json()
 9         arg1= argsJson['arg1']
10         argsJson = arg2 [ ' arg2 ' ]
 . 11          '' ' 
12 is          # format into the reference form
 13 is          arg1 = Request.Form [' arg1 ']
 14          arg2 = Request.Form [' arg2 '] ' '' 
15      the else :
 16          arg1 = Request .args.get ( ' arg1 ' )
 . 17          arg2 = request.args.get ( ' arg2 ' )
 18 is      # call test method 
. 19      RES = test (arg1,
arg2)
20     return res
21 
22 if __name__ == '__main__':
23     app.run(host='0.0.0.0')        

 

 

 

 

Guess you like

Origin www.cnblogs.com/whycai/p/11827996.html