Introduction to Flask, a Python Web Application Framework

Flask is a relatively young one in the Python web framework family. It appeared in 2010, which allowed it to absorb the advantages of other frameworks and define its main field in small projects. Flask is a micro-framework for simple needs and small applications.

The characteristics of Flask can be summarized as follows:

1. Built-in development server and debugger

Network program debugging is the process of testing by hand or compiling a program to correct grammatical and logical errors before putting the compiled website into actual operation. Experienced developers know that this is a necessary step to ensure the official application of the website system.
Flask's own development server eliminates the need for developers to install any other web servers, such as Tomcat, JBoss, Apache, etc., when debugging programs. Flask is in the debugging state by default, so that any errors in the operation will send information to two targets at the same time: one is the Python Console, which is the console for starting the Python program; the other is the HTTP client, that is, the Flask development server transmits debugging information to Up the client.

2. Seamlessly connect with Python unit test function

Unit testing is the testing of the smallest software development unit. It focuses on testing the internal structure of the program, mainly using white box testing methods, and the developer is responsible. The main goal of unit testing is to ensure that the function can get the expected output under a given input state, and to remind the developer to check when it does not meet the requirements.
Flask provides a test interface that seamlessly connects with Python's own unit test framework unitest, that is, the test_client() function of the Flask object. Through the test_client() function, the test program can simulate the client for HTTP access to call the Flask routing processing function, and obtain the output of the function for custom verification.

3. Use Jinja2 template

Linking HTML pages with back-end applications has always been an important goal of the website program framework. Flask solves this problem by using Jinja2 template technology. Jinja2 is a very flexible HTML template technology. It is developed from Django templates, but it is more free and efficient to use than Django templates. Jinja2 template uses a formulated semantic system, provides flexible template inheritance technology, automatically resists XSS cross-site attacks and is easy to debug.

4. Fully compatible with WSGI 1.0 standard

WSGI (Web Server Gateway Interface) is highly scalable and can run in a multi-threaded or multi-process environment. Because of the existence of the Python thread global lock, this feature of WSGI is very important. WSGI is already a major standard in the Python world, and various large web servers have good support for it. WSGI is located between the web application and the web server, and it is fully compatible with WSGI so that Flask can be configured to various large-scale web servers.

5. Based on Unicode encoding
Flask is completely based on Unicode. This is very convenient for making websites with non-pure ASCII character sets. HTTP itself is byte-based, which means that any encoding format can be transmitted in HTTP. However, HTTP requires that the encoding format used in this transmission be explicitly stated in the HTTP Head. By default, Flask will automatically add an HTTP Head in UTF-8 encoding format, so that programmers do not need to worry about encoding issues.

Guess you like

Origin blog.csdn.net/baidu_24752135/article/details/114441342