background:
Provide Web services under Python. The key words and parameters in the URL of the request are handled specifically. Process:
Client->web Server->wsgi->application
The client sends the HTTP request, the Web server waits for receive on the port of an address, once receives, will request passes through WSGI to application processing, application is the FLASK framework writes the application, application after the message processing, also through WSGI returns an HTTP response to the Web server sent to the client by the server.
All flask programs must create an instance of an instance that is an object of the Flask class, and the instance method is created as follows:
From flask import flask
app = Flask (__name__)
Web server
Common Uwsgi, Nginx, Gunicorn, etc.
Flask integrates a Web server for development and can only process one request at a time. Servers that are integrated using flask:
if __name__ = = ' __main__ ':
app.run ()
Code:
#-*-Coding:utf-8-*-from flask import flask to flask Import request from flask Import Make_response from flask impo RT redirect# redirect from flask import Abort #异常抛出 app = Flask (__name__) # matches, intercepts, assigns to the variable name in the URL, the default matching string, and can specify Type. For example,,/user/<int:id> matches only URLs with IDs of integers @app. Route ('/user/<name> ') def hello_world (name): #变量 name as a parameter passed to the function user[off Key parameter] #可以根据不同的name关键字做不同的处理逻辑 if name = = "Print": P1 = Request.args.get (' P1 ', 1, type=int) #从 URL get key to P1
Value is converted to plastic, if no or conversion fails, default is 1 P2 = request.args.get (' P2 ', 1, type=str) return "OK" + str (p1) + "" + str (p2) elif name = = "Return": Print (Request.args) response = make_response ('