Introduction to the Python Flask framework
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
...
Flask
- 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.
- 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.
- Getting started is simple, even if you don’t have much web development experience, you can quickly make a website
- Great for small websites
- Very suitable for developing web services API
- 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
- All aspects of performance are equal to or better than Django
- Django’s own or third-party’s rave reviews, you will always find a third-party library similar to it on Flask
- Flask develops flexibly. Python masters will basically like Flask, but they may have mixed praise and criticism for Django.
- The use of Flask with relational databases is not weaker than Django, and its use with NoSQL databases is far superior to Django
- Flask is more Pythonic than Django and more consistent with Python’s philosophy
Django
- 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.
- Django can develop small applications, but there is always a feeling of "killing a sledgehammer"
- Django's own ORM is very good, and the overall evaluation is slightly higher than SQLAlchemy
- Django's own template engine is simple and easy to use, but its strength and comprehensive evaluation are slightly lower than Jinja
- 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
- Django currently supports unofficial template engines such as Jinja
- 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 - Django is mature, stable, and complete, but compared to Flask, Django's overall ecology is relatively closed
- 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.
- 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:
flask-sqlalchemy
flask-peewee
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:
Flask-MongoEngine
MongoKit
Flask-PyMongo
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
Read previous post:
Read next post:
How Can Your Business Reach Customers Worldwide Quickly and Reliably with An SMS Campaign?
-
-
Alibaba Cloud Community
1,601 posts | 526 followers
Follow
Comments
-
-
Alibaba Cloud Community
1,601 posts | 526 followers
Follow
Related Products
-
ECS(Elastic Compute Service)
Elastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn More -
Domains
Over 20 million domain, free WHOIS privacy protection.
Learn More
More Posts by Alibaba Cloud Community
- QoderWake: Digital Workers Take the Initiative — No Need to @ Every Time
- What Is Model Thinking Effort? Should You Choose Low, High, or Maximum?
- High-Risk PHP and Node.js Vulnerabilities: A Scan Costs Pennies. A Miss Could Cost a Fortune.
- Alibaba Unveils Qwen4-Max: New AI Teammate for Work, Creativity, and Discovery
- Alibaba Brings Cloud and AI to the First Youth Olympic Games in Africa
- Introducing Qoder Lite: Start creating with Qoder for $10 a month
- Qoder Fast: Keeping Pace with Your Thoughts
- Qoder Cloud Agents: An Evaluation Loop for Reliable, Continuous Agent Improvement
- Making Fast Mode Faster
- Your Database's Biggest User Is Now an Agent — and That Changes Security