Skip to main content

Flask Web Framework

The Python microframework for building web applications your way.

Overview

Flask is a lightweight WSGI web application framework in Python. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks.

Flask is considered a "microframework" because it aims to keep the core simple but extensible. It doesn't make many decisions for you, such as which database to use or what project layout to follow. Instead, Flask leaves those choices up to you, so you can build your application exactly the way you want it. Its extensive ecosystem of extensions makes it easy to add any functionality you need.

Key Concepts

  • Application Object Initializing the Application: The central Flask instance that acts as the heart of your application. It manages configuration, URL rules, template lookups, and the WSGI dispatching process.
  • Routing Registering Routes and Handlers: The system that maps URLs to the Python functions that handle them. This is primarily done using the @app.route() decorator, which makes it intuitive to connect your code to specific web endpoints.
  • Blueprints Blueprints & Modular Design: A powerful way to structure your application into smaller, reusable components. Blueprints allow you to organize related views, templates, and static files, making your codebase more modular and scalable as it grows.
  • Contexts The Unified Context System: The mechanism that allows Flask to provide access to objects like the current request and application without passing them around to every function. Understanding application and request contexts is key to mastering how Flask works under the hood.
  • Templating with Jinja Templating & Rendering: Flask's built-in integration with the Jinja2 templating engine. This allows you to build dynamic HTML pages by embedding Python-like expressions and logic directly into your templates.
  • Command-Line Interface (CLI) Getting Started with the Flask CLI: A set of tools, powered by Click, for running the development server, managing application contexts in a shell, and creating custom management commands for your project.

Common Use Cases

  • Building RESTful APIs and microservices.
  • Developing dynamic websites, from simple blogs to complex platforms.
  • Creating backend services for single-page applications (SPAs).
  • Rapidly prototyping web-based tools and dashboards.

Getting Started

New to Flask? The best place to start is the Getting Started guide, which will walk you through installing Flask and building your first application. From there, you can dive into core topics like Core Application & Configuration and Request & Response Handling to build a solid foundation.