flask
. 1 Import Flask 2 from Flask Import jsonify . 3 from Flask Import Request # to the acquired request parameters, then it would import this module . 4 . 5 '' ' 6 create an interface service, Format: flask.Flask (__ name__), similar redis.Redis , 7 of which (__name__) refers to the current python file, that interface is based on this document in the run 8 '' ' 9 Server = flask.Flask ( __name__ ) 10 # after creating the interface service, you need to specify the path, path contains suffix and a request method, and if necessary @ decoration, following function to operate properly . 11 @ server.route ( ' / Login ' , methods = [ ' GET ' ,' POST ' ]) # routing request method 12 is DEF REG (): # interface body portion, the operation content 13 is # request.values Gets the value of parameter passing, for determination, the process 14 Print (request.values) 15 # call If the interface parameter passed is passed json type parameter, is request.json.get ( "username") 16 username = request.values.get ( ' username ' ) . 17 # call parameters passed in the interface 18 is password = Request. be values.get ( ' password ' ) . 19 Print (username, password) 20 is return jsonify ({" Code " : 0, " msg " : " the Login Success " }) 21 22 IF __name__ == ' __main__ ' : 23 # service is created, and specify the good path, after the write interface content, you need to start the service, start time you need to specify port 24 # you can also specify host as "0.0.0.0", the LAN can access other IP on the 25 server.run (port = 9999, Debug = True) # start the service
operation result:
Visit: http: //127.0.0.1:? 9999 / login username = test & password = 123456