Community Blog Introduction to the Python Flask framework

Introduction to the Python Flask framework

Flask is a lightweight framework. The most basic form of Flask application only involves URL routing, and it can work without configuring anything.

Introduction to the Python Flask framework

Flask is a lightweight web application framework written in Python. Based on Werkzeug WSGI (Python Web Server Gateway Interface (WSGI) is an interface between a Python application or framework and a Web server. It has been widely accepted, and it has basically achieved its portability. The goal) toolbox and Jinja2 template engine. Flask uses BSD authorization. Flask is also called "microframework" because it uses a simple core and uses extensions to add other functions. Flask does not have a default database or form verification tool. However, Flask retains the flexibility of expansion, and Flask-extension can be used to add these functions: ORM, form verification tools, file uploads, and various open authentication technologies.

What can be done with the Flask framework

From blogging applications to cloning a facebook or twitter, in theory you can do anything with Flask. There are many libraries that can be used directly, such as flask-sockets, flask-google-maps, etc., and the Flask framework supports MySQL, Postgresql, MongoDB and many other databases.

The difference between Flask and Django

Django and Flask are the two Python web frameworks with the largest number of stars on GitHub. There are also many articles on the Internet that analyze and compare these two web frameworks, such as:

Quora: Should I learn Flask or Django?
Django vs Flask vs Pyramid: Choosing a Python Web Framework


  1. Flask is indeed very "light", worthy of the Micro Framework. Developers who switch from Django to Flask will definitely feel so emotional, unless both have been used in depth.
  2. Flask is free, flexible, and extensible. It has a wide selection of third-party libraries. You can combine your favorite wheels during development, and you can also combine the most popular and powerful Python libraries.
  3. Getting started is simple, even if you don’t have much web development experience, you can quickly make a website
  4. Great for small websites
  5. Very suitable for developing web services API
  6. There is no pressure to develop large-scale websites, but the code structure needs to be designed by yourself, and the development cost depends on the developer's ability and experience
  7. All aspects of performance are equal to or better than Django
  8. Django’s own or third-party’s rave reviews, you will always find a third-party library similar to it on Flask
  9. Flask develops flexibly. Python masters will basically like Flask, but they may have mixed praise and criticism for Django.
  10. The use of Flask with relational databases is not weaker than Django, and its use with NoSQL databases is far superior to Django
  11. Flask is more Pythonic than Django and more consistent with Python’s philosophy


  1. Django is too heavy. In addition to the web framework, it has its own ORM and template engine, so its flexibility and freedom are not high enough.
  2. Django can develop small applications, but there is always a feeling of "killing a sledgehammer"
  3. Django's own ORM is very good, and the overall evaluation is slightly higher than SQLAlchemy
  4. Django's own template engine is simple and easy to use, but its strength and comprehensive evaluation are slightly lower than Jinja
  5. Django's built-in ORM also makes Django and relational database coupled too high. If you want to use NoSQL data such as MongoDB, you need to choose a suitable third-party library, and I always feel that Django+SQL is a natural match. Django+NoSQL cuts Lost half of Django
  6. Django currently supports unofficial template engines such as Jinja
  7. Django's own database management app has received rave reviews
    Django is very suitable for the development of enterprise-level websites: fast, reliable, and stable
  8. Django is mature, stable, and complete, but compared to Flask, Django's overall ecology is relatively closed
  9. Django is the pioneer of the Python web framework. It has many users, the most abundant third-party libraries, and the best Python library. If you can't directly use Django, you can definitely find a corresponding port.
  10. Django is also relatively easy to get started, with detailed and complete development documentation, and abundant relevant information

Flask and database

Most websites use database software to store data, and databases are crucial to any application.

Although Flask is directly connected to the database to access data, there is no problem, but it will make the application and the database tightly coupled, which is not conducive to expansion, and will increase the workload of maintaining code logic. Using the database abstraction layer will simplify the logic of Flask's interaction with the database, and transfer the logic of Flask's interaction with the database to the database abstraction layer to make business logic clearer and more focused on development. Since Flask is a Micro Framework, there is no database abstraction layer itself, and there are many database abstraction layers available under the Python ecosystem. For Flask, there are many options. Developers can choose the best or most familiar database abstraction layer. Applied to development.

Database abstraction layer for relational databases

The database abstraction layer and ORM (Object Relation Mapping) applicable to relational databases, applicable to Flask include:

Database abstraction layer for NoSQL databases

There are many NoSQL databases. MongoDB is one of the document-based NoSQL databases. Since MongoDB is born to serve the Internet, I have only used Flask + MongoDB for development. Only the abstraction layer of MongoDB is listed below:

Related Articles and Resources

Blog> Setting Up a Flask Application on Alibaba Cloud ECS Ubuntu 16.04

In this guide, we will be installing Flask and running a sample application on Alibaba Cloud ECS with Ubuntu 16.04.

Documentation> Use Flask to develop applications

Flask is a Python-based light-weight Web framework. This topic describes how to use Flask to create an application and deploy the application in Web+.

Course > A Demo to Install Flask App on ECS

0 0 0
Share on

Alibaba Cloud Community

817 posts | 182 followers

You may also like