Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Flask Introduction

Flask Introduction

Flask is a lightweight Python web application framework, developed and maintained by the Pallets organization.

It is known for being simple and flexible, letting you quickly get started building web applications while still having the ability to scale to complex projects.

Flask is a micro web framework developed in Python. It is called a microframework mainly because it does not bundle any specialized tools or dependency libraries, and does not natively include common web components such as a database abstraction layer or form validation.

Flask has good extension support, allowing you to add functional plugins as needed. There are mature extensions for ORM (object-relational mapping), form validation, file uploads, open authentication, and various supporting development tools, which can fill in the functionality your project requires.


What Is Flask

Flask is a WSGI (Web Server Gateway Interface) web application framework.

WSGI is a standard interface defined by Python that specifies how web servers communicate with Python web applications. You can think of it as the 'universal socket' of the Python web world.

Flask originally was just a simple wrapper layer around Werkzeug and Jinja, and has now become one of the most popular web frameworks in the Python community.


Core dependency

When you install Flask, the following dependencies are automatically installed, each with its own role:

Dependency Library Purpose When You'll Encounter It
Werkzeug WSGI utility library, responsible for HTTP request parsing, response wrapping, and URL routing matching When handling requests and returning responses, Werkzeug is working under the hood
Jinja2 Template engine, responsible for rendering data into HTML pages When using render_template() to generate dynamic pages
Click Command-line tool framework, providing the flask terminal command When running flask run or custom CLI commands
itsdangerous Data signing library, ensuring data integrity is not tampered with Signature verification of Session cookies
blinker Signals mechanism, allowing callbacks to be triggered when specific events occur When you want to execute custom logic at the start/end of a request

Understanding and Memorization: Think of Flask as a car: Werkzeug is the engine (core power), Jinja2 is the interior (what users see), Click is the steering wheel (how you control it), and itsdangerous is the seat belt (safety guarantee).


Flask's Design Philosophy

Flask's two core concepts determine how it is used.

Microframework, Not Micro Capabilities

Flask's core is very lean, but through its rich extension ecosystem it can meet almost any need.

It does not force you to use a specific database, form library, or project structure—developers choose the tools that best suit them.

This design means: small projects are not weighed down by the framework, while large projects can be assembled as needed.

Explicit Is Better Than Implicit

Unlike some 'batteries-included' frameworks, Flask doesn't secretly do a lot of things for you.

Every feature needs to be explicitly imported and configured by you, which may require a few more lines of code when you're starting out, but gives you complete control over the project.

If you've used Django before, you might feel that Flask 'makes you do everything yourself.' That is exactly Flask's design intent: to let you clearly know where every feature comes from.


Flask Features

If you've used Django before, you might feel that Flask 'makes you do everything yourself.' That is exactly Flask's design intent: to let you clearly know where every feature comes from and have complete control over the project.


Flask Use Cases


Flask's Components

/Users/tianqixin/runoob-test/runoob-article/2026-05-13/images/flask-architecture.svg


Technology Stack Overview

The following diagram shows the typical layered structure of a Flask application, helping you understand the position of each component as a whole:

Flask Technology Stack Layered Architecture