1. Introduction to Flask

Web application role

  • The original purpose of the Web (World Wide Web) was to use the Internet to exchange work documents.
    insert image description here
  • client (client) can be any networked device that can send requests to the server.
  • One response is requested at a time, and there are as many responses as there are requests.
  • The client does not initiate a request, and the server cannot actively send response data to the client.

About web frameworks

1. What is a Web framework?

  1. A piece of code has been packaged to assist the rapid development of the program, which is equivalent to a semi-finished project.
  2. Developers only need to write their own business logic codes in the designated positions according to the requirements of the framework agreement.
    • For example: a hospital needs to be established in a certain district, there are two ways:
      1. Enclosure, foundation laying, building, decoration, moving in.
      2. Buy a building, decorate, move in.

Second, why use a Web framework?

  1. Since the development of the Web site, especially the server side, the knowledge and content of the design are very extensive. The requirements for programmers will be higher and higher. If a mature and robust framework is adopted, then some basic work, such as security and data flow control, can be handled by the framework.
  2. Program developers can focus on specific business logic.
  • Summary: Reduce the difficulty of development, improve development efficiency, and do not need to reinvent the wheel.

3. Web frameworks and their characteristics commonly used in Python

  1. flask: Provides basic functions and is lightweight. (It does not provide complex functions, such as site management and database connection, and requires the installation of other modules to achieve.)
  2. djiango: Provides relatively complete functions, heavyweight. (Provides various functions including site management and database connection, which can be used to efficiently create large-scale websites and large-scale applications.)
  3. tornado: partial embedded web application, non-blocking server. (It comes with high concurrent processing capabilities, and multiple user accesses will automatically open multiple processes for processing at the same time)

4. About Flask

  • Birth time: Flask was born in 2010. It is a lightweight web development framework written by Armin ronacher in Python language based on the Werkzeug toolbox.
  • The Flask framework includes two cores: the Werkzeug toolbox (specially used to process request-related content), and the Jinja2 template engine (used for page rendering).
  • Since Flask does not provide additional functions, almost all functions need to be extended (used to handle database connections, site management, database migration, and cache processing (flask-cache)).

Flask common extension package

  • Flask-SQLalchemy: operate the database;
  • Flask-script: insert script;
  • Flask-migrate: manage migration database;
  • Flask-Session: Session storage method specified;
  • Flask-WTF: form;
  • Flask-Mail: mail;
  • Flask-Bable: provides internationalization and localization support, translation;
  • Flask-Login: authenticated user status;
  • Flask-OpenID: authentication;
  • Flask-RESTful: a tool for developing REST API;
  • Flask-Bootstrap: integrated front-end Twitter Bootstrap framework;
  • Flask-Moment: localize date and time;
  • Flask-Admin: A framework for simple and extensible admin interfaces.

More extension list: http://flask.pocoo.org/extensions/

Usually we can install any extensions for whatever functions we need, and we don’t need to install all of them, it’s not necessary.

  1. Flask Chinese documentation ( http://docs.jinkan.org/docs/flask/ )
  2. Flask English documentation ( https://flask.palletsprojects.com/en/2.3.x/ )

Guess you like

Origin blog.csdn.net/ungoing/article/details/130946193