Python Learning notes-Web service offerings based on flask

Source: Internet
Author: User
Tags instance method
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 (' 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.