# Table of Contents - [Welcome to Flask — Flask Documentation (3.1.x)](#welcome-to-flask-flask-documentation-3-1-x-) - [Index — Flask Documentation (3.1.x)](#index-flask-documentation-3-1-x-) - [Installation — Flask Documentation (3.1.x)](#installation-flask-documentation-3-1-x-) - [Quickstart — Flask Documentation (3.1.x)](#quickstart-flask-documentation-3-1-x-) - [Tutorial — Flask Documentation (3.1.x)](#tutorial-flask-documentation-3-1-x-) - [Python Module Index — Flask Documentation (3.1.x)](#python-module-index-flask-documentation-3-1-x-) - [Patterns for Flask — Flask Documentation (3.1.x)](#patterns-for-flask-flask-documentation-3-1-x-) - [Project Layout — Flask Documentation (3.1.x)](#project-layout-flask-documentation-3-1-x-) - [Templates — Flask Documentation (3.1.x)](#templates-flask-documentation-3-1-x-) - [Static Files — Flask Documentation (3.1.x)](#static-files-flask-documentation-3-1-x-) - [Signals — Flask Documentation (3.1.x)](#signals-flask-documentation-3-1-x-) - [Blog Blueprint — Flask Documentation (3.1.x)](#blog-blueprint-flask-documentation-3-1-x-) - [Make the Project Installable — Flask Documentation (3.1.x)](#make-the-project-installable-flask-documentation-3-1-x-) - [API — Flask Documentation (3.1.x)](#api-flask-documentation-3-1-x-) - [Blueprints and Views — Flask Documentation (3.1.x)](#blueprints-and-views-flask-documentation-3-1-x-) - [Application Setup — Flask Documentation (3.1.x)](#application-setup-flask-documentation-3-1-x-) - [Define and Access the Database — Flask Documentation (3.1.x)](#define-and-access-the-database-flask-documentation-3-1-x-) - [Deploy to Production — Flask Documentation (3.1.x)](#deploy-to-production-flask-documentation-3-1-x-) - [Test Coverage — Flask Documentation (3.1.x)](#test-coverage-flask-documentation-3-1-x-) - [Templates — Flask Documentation (3.1.x)](#templates-flask-documentation-3-1-x-) - [Testing Flask Applications — Flask Documentation (3.1.x)](#testing-flask-applications-flask-documentation-3-1-x-) - [Keep Developing! — Flask Documentation (3.1.x)](#keep-developing-flask-documentation-3-1-x-) - [Debugging Application Errors — Flask Documentation (3.1.x)](#debugging-application-errors-flask-documentation-3-1-x-) - [Handling Application Errors — Flask Documentation (3.1.x)](#handling-application-errors-flask-documentation-3-1-x-) - [Logging — Flask Documentation (3.1.x)](#logging-flask-documentation-3-1-x-) - [The Application Context — Flask Documentation (3.1.x)](#the-application-context-flask-documentation-3-1-x-) - [Configuration Handling — Flask Documentation (3.1.x)](#configuration-handling-flask-documentation-3-1-x-) - [The Request Context — Flask Documentation (3.1.x)](#the-request-context-flask-documentation-3-1-x-) - [Class-based Views — Flask Documentation (3.1.x)](#class-based-views-flask-documentation-3-1-x-) - [Command Line Interface — Flask Documentation (3.1.x)](#command-line-interface-flask-documentation-3-1-x-) - [Modular Applications with Blueprints — Flask Documentation (3.1.x)](#modular-applications-with-blueprints-flask-documentation-3-1-x-) - [Application Structure and Lifecycle — Flask Documentation (3.1.x)](#application-structure-and-lifecycle-flask-documentation-3-1-x-) - [Development Server — Flask Documentation (3.1.x)](#development-server-flask-documentation-3-1-x-) - [Extensions — Flask Documentation (3.1.x)](#extensions-flask-documentation-3-1-x-) - [Application Factories — Flask Documentation (3.1.x)](#application-factories-flask-documentation-3-1-x-) - [Working with the Shell — Flask Documentation (3.1.x)](#working-with-the-shell-flask-documentation-3-1-x-) - [Large Applications as Packages — Flask Documentation (3.1.x)](#large-applications-as-packages-flask-documentation-3-1-x-) - [Using SQLite 3 with Flask — Flask Documentation (3.1.x)](#using-sqlite-3-with-flask-flask-documentation-3-1-x-) - [Using URL Processors — Flask Documentation (3.1.x)](#using-url-processors-flask-documentation-3-1-x-) - [SQLAlchemy in Flask — Flask Documentation (3.1.x)](#sqlalchemy-in-flask-flask-documentation-3-1-x-) - [Application Dispatching — Flask Documentation (3.1.x)](#application-dispatching-flask-documentation-3-1-x-) - [Uploading Files — Flask Documentation (3.1.x)](#uploading-files-flask-documentation-3-1-x-) - [View Decorators — Flask Documentation (3.1.x)](#view-decorators-flask-documentation-3-1-x-) - [Caching — Flask Documentation (3.1.x)](#caching-flask-documentation-3-1-x-) - [Form Validation with WTForms — Flask Documentation (3.1.x)](#form-validation-with-wtforms-flask-documentation-3-1-x-) - [Template Inheritance — Flask Documentation (3.1.x)](#template-inheritance-flask-documentation-3-1-x-) - [Message Flashing — Flask Documentation (3.1.x)](#message-flashing-flask-documentation-3-1-x-) - [JavaScript, fetch, and JSON — Flask Documentation (3.1.x)](#javascript-fetch-and-json-flask-documentation-3-1-x-) - [Adding a favicon — Flask Documentation (3.1.x)](#adding-a-favicon-flask-documentation-3-1-x-) - [MongoDB with MongoEngine — Flask Documentation (3.1.x)](#mongodb-with-mongoengine-flask-documentation-3-1-x-) - [Lazily Loading Views — Flask Documentation (3.1.x)](#lazily-loading-views-flask-documentation-3-1-x-) - [Streaming Contents — Flask Documentation (3.1.x)](#streaming-contents-flask-documentation-3-1-x-) - [Deferred Request Callbacks — Flask Documentation (3.1.x)](#deferred-request-callbacks-flask-documentation-3-1-x-) - [Subclassing Flask — Flask Documentation (3.1.x)](#subclassing-flask-flask-documentation-3-1-x-) - [Deploying to Production — Flask Documentation (3.1.x)](#deploying-to-production-flask-documentation-3-1-x-) - [Background Tasks with Celery — Flask Documentation (3.1.x)](#background-tasks-with-celery-flask-documentation-3-1-x-) - [Adding HTTP Method Overrides — Flask Documentation (3.1.x)](#adding-http-method-overrides-flask-documentation-3-1-x-) - [Request Content Checksums — Flask Documentation (3.1.x)](#request-content-checksums-flask-documentation-3-1-x-) - [Single-Page Applications — Flask Documentation (3.1.x)](#single-page-applications-flask-documentation-3-1-x-) - [Security Considerations — Flask Documentation (3.1.x)](#security-considerations-flask-documentation-3-1-x-) - [Flask Extension Development — Flask Documentation (3.1.x)](#flask-extension-development-flask-documentation-3-1-x-) - [Design Decisions in Flask — Flask Documentation (3.1.x)](#design-decisions-in-flask-flask-documentation-3-1-x-) - [Contributing — Flask Documentation (3.1.x)](#contributing-flask-documentation-3-1-x-) - [Using async and await — Flask Documentation (3.1.x)](#using-async-and-await-flask-documentation-3-1-x-) - [BSD-3-Clause License — Flask Documentation (3.1.x)](#bsd-3-clause-license-flask-documentation-3-1-x-) - [Gunicorn — Flask Documentation (3.1.x)](#gunicorn-flask-documentation-3-1-x-) - [Waitress — Flask Documentation (3.1.x)](#waitress-flask-documentation-3-1-x-) - [mod_wsgi — Flask Documentation (3.1.x)](#mod-wsgi-flask-documentation-3-1-x-) - [eventlet — Flask Documentation (3.1.x)](#eventlet-flask-documentation-3-1-x-) - [uWSGI — Flask Documentation (3.1.x)](#uwsgi-flask-documentation-3-1-x-) - [Changes — Flask Documentation (3.1.x)](#changes-flask-documentation-3-1-x-) - [Tell Flask it is Behind a Proxy — Flask Documentation (3.1.x)](#tell-flask-it-is-behind-a-proxy-flask-documentation-3-1-x-) - [gevent — Flask Documentation (3.1.x)](#gevent-flask-documentation-3-1-x-) - [ASGI — Flask Documentation (3.1.x)](#asgi-flask-documentation-3-1-x-) - [Apache httpd — Flask Documentation (3.1.x)](#apache-httpd-flask-documentation-3-1-x-) - [nginx — Flask Documentation (3.1.x)](#nginx-flask-documentation-3-1-x-) - [Page Not Found — Flask Documentation (3.1.x)](#page-not-found-flask-documentation-3-1-x-) --- # Welcome to Flask — Flask Documentation (3.1.x) ### Navigation * [index](genindex/ "General Index") * [modules](py-modindex/ "Python Module Index") | * [next](installation/ "Installation") | * [Flask Documentation (3.1.x)](#) » * Welcome to Flask Welcome to Flask[¶](#welcome-to-flask "Link to this heading") ============================================================== ![_images/flask-horizontal.png](_images/flask-horizontal.png) Welcome to Flask’s documentation. Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Get started with [Installation](installation/) and then get an overview with the [Quickstart](quickstart/) . There is also a more detailed [Tutorial](tutorial/) that shows how to create a small but complete application with Flask. Common patterns are described in the [Patterns for Flask](patterns/) section. The rest of the docs describe each component of Flask in detail, with a full reference in the [API](api/) section. Flask depends on the [Werkzeug](https://werkzeug.palletsprojects.com) WSGI toolkit, the [Jinja](https://jinja.palletsprojects.com) template engine, and the [Click](https://click.palletsprojects.com) CLI toolkit. Be sure to check their documentation as well as Flask’s when looking for information. User’s Guide[¶](#user-s-guide "Link to this heading") ------------------------------------------------------ Flask provides configuration and conventions, with sensible defaults, to get started. This section of the documentation explains the different parts of the Flask framework and how they can be used, customized, and extended. Beyond Flask itself, look for community-maintained extensions to add even more functionality. * [Installation](installation/) * [Python Version](installation/#python-version) * [Dependencies](installation/#dependencies) * [Virtual environments](installation/#virtual-environments) * [Install Flask](installation/#install-flask) * [Quickstart](quickstart/) * [A Minimal Application](quickstart/#a-minimal-application) * [Debug Mode](quickstart/#debug-mode) * [HTML Escaping](quickstart/#html-escaping) * [Routing](quickstart/#routing) * [Static Files](quickstart/#static-files) * [Rendering Templates](quickstart/#rendering-templates) * [Accessing Request Data](quickstart/#accessing-request-data) * [Redirects and Errors](quickstart/#redirects-and-errors) * [About Responses](quickstart/#about-responses) * [Sessions](quickstart/#sessions) * [Message Flashing](quickstart/#message-flashing) * [Logging](quickstart/#logging) * [Hooking in WSGI Middleware](quickstart/#hooking-in-wsgi-middleware) * [Using Flask Extensions](quickstart/#using-flask-extensions) * [Deploying to a Web Server](quickstart/#deploying-to-a-web-server) * [Tutorial](tutorial/) * [Project Layout](tutorial/layout/) * [Application Setup](tutorial/factory/) * [Define and Access the Database](tutorial/database/) * [Blueprints and Views](tutorial/views/) * [Templates](tutorial/templates/) * [Static Files](tutorial/static/) * [Blog Blueprint](tutorial/blog/) * [Make the Project Installable](tutorial/install/) * [Test Coverage](tutorial/tests/) * [Deploy to Production](tutorial/deploy/) * [Keep Developing!](tutorial/next/) * [Templates](templating/) * [Jinja Setup](templating/#jinja-setup) * [Standard Context](templating/#standard-context) * [Controlling Autoescaping](templating/#controlling-autoescaping) * [Registering Filters](templating/#registering-filters) * [Context Processors](templating/#context-processors) * [Streaming](templating/#streaming) * [Testing Flask Applications](testing/) * [Identifying Tests](testing/#identifying-tests) * [Fixtures](testing/#fixtures) * [Sending Requests with the Test Client](testing/#sending-requests-with-the-test-client) * [Following Redirects](testing/#following-redirects) * [Accessing and Modifying the Session](testing/#accessing-and-modifying-the-session) * [Running Commands with the CLI Runner](testing/#running-commands-with-the-cli-runner) * [Tests that depend on an Active Context](testing/#tests-that-depend-on-an-active-context) * [Handling Application Errors](errorhandling/) * [Error Logging Tools](errorhandling/#error-logging-tools) * [Error Handlers](errorhandling/#error-handlers) * [Custom Error Pages](errorhandling/#custom-error-pages) * [Blueprint Error Handlers](errorhandling/#blueprint-error-handlers) * [Returning API Errors as JSON](errorhandling/#returning-api-errors-as-json) * [Logging](errorhandling/#logging) * [Debugging](errorhandling/#debugging) * [Debugging Application Errors](debugging/) * [In Production](debugging/#in-production) * [The Built-In Debugger](debugging/#the-built-in-debugger) * [External Debuggers](debugging/#external-debuggers) * [Logging](logging/) * [Basic Configuration](logging/#basic-configuration) * [Email Errors to Admins](logging/#email-errors-to-admins) * [Injecting Request Information](logging/#injecting-request-information) * [Other Libraries](logging/#other-libraries) * [Configuration Handling](config/) * [Configuration Basics](config/#configuration-basics) * [Debug Mode](config/#debug-mode) * [Builtin Configuration Values](config/#builtin-configuration-values) * [Configuring from Python Files](config/#configuring-from-python-files) * [Configuring from Data Files](config/#configuring-from-data-files) * [Configuring from Environment Variables](config/#configuring-from-environment-variables) * [Configuration Best Practices](config/#configuration-best-practices) * [Development / Production](config/#development-production) * [Instance Folders](config/#instance-folders) * [Signals](signals/) * [Core Signals](signals/#core-signals) * [Subscribing to Signals](signals/#subscribing-to-signals) * [Creating Signals](signals/#creating-signals) * [Sending Signals](signals/#sending-signals) * [Signals and Flask’s Request Context](signals/#signals-and-flask-s-request-context) * [Decorator Based Signal Subscriptions](signals/#decorator-based-signal-subscriptions) * [Class-based Views](views/) * [Basic Reusable View](views/#basic-reusable-view) * [URL Variables](views/#url-variables) * [View Lifetime and `self`](views/#view-lifetime-and-self) * [View Decorators](views/#view-decorators) * [Method Hints](views/#method-hints) * [Method Dispatching and APIs](views/#method-dispatching-and-apis) * [Application Structure and Lifecycle](lifecycle/) * [Application Setup](lifecycle/#application-setup) * [Serving the Application](lifecycle/#serving-the-application) * [How a Request is Handled](lifecycle/#how-a-request-is-handled) * [The Application Context](appcontext/) * [Purpose of the Context](appcontext/#purpose-of-the-context) * [Lifetime of the Context](appcontext/#lifetime-of-the-context) * [Manually Push a Context](appcontext/#manually-push-a-context) * [Storing Data](appcontext/#storing-data) * [Events and Signals](appcontext/#events-and-signals) * [The Request Context](reqcontext/) * [Purpose of the Context](reqcontext/#purpose-of-the-context) * [Lifetime of the Context](reqcontext/#lifetime-of-the-context) * [Manually Push a Context](reqcontext/#manually-push-a-context) * [How the Context Works](reqcontext/#how-the-context-works) * [Callbacks and Errors](reqcontext/#callbacks-and-errors) * [Notes On Proxies](reqcontext/#notes-on-proxies) * [Modular Applications with Blueprints](blueprints/) * [Why Blueprints?](blueprints/#why-blueprints) * [The Concept of Blueprints](blueprints/#the-concept-of-blueprints) * [My First Blueprint](blueprints/#my-first-blueprint) * [Registering Blueprints](blueprints/#registering-blueprints) * [Nesting Blueprints](blueprints/#nesting-blueprints) * [Blueprint Resources](blueprints/#blueprint-resources) * [Building URLs](blueprints/#building-urls) * [Blueprint Error Handlers](blueprints/#blueprint-error-handlers) * [Extensions](extensions/) * [Finding Extensions](extensions/#finding-extensions) * [Using Extensions](extensions/#using-extensions) * [Building Extensions](extensions/#building-extensions) * [Command Line Interface](cli/) * [Application Discovery](cli/#application-discovery) * [Run the Development Server](cli/#run-the-development-server) * [Open a Shell](cli/#open-a-shell) * [Environment Variables From dotenv](cli/#environment-variables-from-dotenv) * [Environment Variables From virtualenv](cli/#environment-variables-from-virtualenv) * [Custom Commands](cli/#custom-commands) * [Plugins](cli/#plugins) * [Custom Scripts](cli/#custom-scripts) * [PyCharm Integration](cli/#pycharm-integration) * [Development Server](server/) * [Command Line](server/#command-line) * [In Code](server/#in-code) * [Working with the Shell](shell/) * [Command Line Interface](shell/#command-line-interface) * [Creating a Request Context](shell/#creating-a-request-context) * [Firing Before/After Request](shell/#firing-before-after-request) * [Further Improving the Shell Experience](shell/#further-improving-the-shell-experience) * [Patterns for Flask](patterns/) * [Large Applications as Packages](patterns/packages/) * [Application Factories](patterns/appfactories/) * [Application Dispatching](patterns/appdispatch/) * [Using URL Processors](patterns/urlprocessors/) * [Using SQLite 3 with Flask](patterns/sqlite3/) * [SQLAlchemy in Flask](patterns/sqlalchemy/) * [Uploading Files](patterns/fileuploads/) * [Caching](patterns/caching/) * [View Decorators](patterns/viewdecorators/) * [Form Validation with WTForms](patterns/wtforms/) * [Template Inheritance](patterns/templateinheritance/) * [Message Flashing](patterns/flashing/) * [JavaScript, `fetch`, and JSON](patterns/javascript/) * [Lazily Loading Views](patterns/lazyloading/) * [MongoDB with MongoEngine](patterns/mongoengine/) * [Adding a favicon](patterns/favicon/) * [Streaming Contents](patterns/streaming/) * [Deferred Request Callbacks](patterns/deferredcallbacks/) * [Adding HTTP Method Overrides](patterns/methodoverrides/) * [Request Content Checksums](patterns/requestchecksum/) * [Background Tasks with Celery](patterns/celery/) * [Subclassing Flask](patterns/subclassing/) * [Single-Page Applications](patterns/singlepageapplications/) * [Security Considerations](web-security/) * [Resource Use](web-security/#resource-use) * [Cross-Site Scripting (XSS)](web-security/#cross-site-scripting-xss) * [Cross-Site Request Forgery (CSRF)](web-security/#cross-site-request-forgery-csrf) * [JSON Security](web-security/#json-security) * [Security Headers](web-security/#security-headers) * [Copy/Paste to Terminal](web-security/#copy-paste-to-terminal) * [Deploying to Production](deploying/) * [Self-Hosted Options](deploying/#self-hosted-options) * [Hosting Platforms](deploying/#hosting-platforms) * [Using `async` and `await`](async-await/) * [Performance](async-await/#performance) * [Background tasks](async-await/#background-tasks) * [When to use Quart instead](async-await/#when-to-use-quart-instead) * [Extensions](async-await/#extensions) * [Other event loops](async-await/#other-event-loops) API Reference[¶](#api-reference "Link to this heading") -------------------------------------------------------- If you are looking for information on a specific function, class or method, this part of the documentation is for you. * [API](api/) * [Application Object](api/#application-object) * [Blueprint Objects](api/#blueprint-objects) * [Incoming Request Data](api/#incoming-request-data) * [Response Objects](api/#response-objects) * [Sessions](api/#sessions) * [Session Interface](api/#session-interface) * [Test Client](api/#test-client) * [Test CLI Runner](api/#test-cli-runner) * [Application Globals](api/#application-globals) * [Useful Functions and Classes](api/#useful-functions-and-classes) * [Message Flashing](api/#message-flashing) * [JSON Support](api/#module-flask.json) * [Template Rendering](api/#template-rendering) * [Configuration](api/#configuration) * [Stream Helpers](api/#stream-helpers) * [Useful Internals](api/#useful-internals) * [Signals](api/#signals) * [Class-Based Views](api/#class-based-views) * [URL Route Registrations](api/#url-route-registrations) * [View Function Options](api/#view-function-options) * [Command Line Interface](api/#command-line-interface) Additional Notes[¶](#additional-notes "Link to this heading") -------------------------------------------------------------- * [Design Decisions in Flask](design/) * [The Explicit Application Object](design/#the-explicit-application-object) * [The Routing System](design/#the-routing-system) * [One Template Engine](design/#one-template-engine) * [What does “micro” mean?](design/#what-does-micro-mean) * [Thread Locals](design/#thread-locals) * [Async/await and ASGI support](design/#async-await-and-asgi-support) * [What Flask is, What Flask is Not](design/#what-flask-is-what-flask-is-not) * [Flask Extension Development](extensiondev/) * [Naming](extensiondev/#naming) * [The Extension Class and Initialization](extensiondev/#the-extension-class-and-initialization) * [Adding Behavior](extensiondev/#adding-behavior) * [Configuration Techniques](extensiondev/#configuration-techniques) * [Data During a Request](extensiondev/#data-during-a-request) * [Views and Models](extensiondev/#views-and-models) * [Recommended Extension Guidelines](extensiondev/#recommended-extension-guidelines) * [Contributing](contributing/) * [BSD-3-Clause License](license/) * [Changes](changes/) * [Version 3.1.1](changes/#version-3-1-1) * [Version 3.1.0](changes/#version-3-1-0) * [Version 3.0.3](changes/#version-3-0-3) * [Version 3.0.2](changes/#version-3-0-2) * [Version 3.0.1](changes/#version-3-0-1) * [Version 3.0.0](changes/#version-3-0-0) * [Version 2.3.3](changes/#version-2-3-3) * [Version 2.3.2](changes/#version-2-3-2) * [Version 2.3.1](changes/#version-2-3-1) * [Version 2.3.0](changes/#version-2-3-0) * [Version 2.2.5](changes/#version-2-2-5) * [Version 2.2.4](changes/#version-2-2-4) * [Version 2.2.3](changes/#version-2-2-3) * [Version 2.2.2](changes/#version-2-2-2) * [Version 2.2.1](changes/#version-2-2-1) * [Version 2.2.0](changes/#version-2-2-0) * [Version 2.1.3](changes/#version-2-1-3) * [Version 2.1.2](changes/#version-2-1-2) * [Version 2.1.1](changes/#version-2-1-1) * [Version 2.1.0](changes/#version-2-1-0) * [Version 2.0.3](changes/#version-2-0-3) * [Version 2.0.2](changes/#version-2-0-2) * [Version 2.0.1](changes/#version-2-0-1) * [Version 2.0.0](changes/#version-2-0-0) * [Version 1.1.4](changes/#version-1-1-4) * [Version 1.1.3](changes/#version-1-1-3) * [Version 1.1.2](changes/#version-1-1-2) * [Version 1.1.1](changes/#version-1-1-1) * [Version 1.1.0](changes/#version-1-1-0) * [Version 1.0.4](changes/#version-1-0-4) * [Version 1.0.3](changes/#version-1-0-3) * [Version 1.0.2](changes/#version-1-0-2) * [Version 1.0.1](changes/#version-1-0-1) * [Version 1.0](changes/#version-1-0) * [Version 0.12.5](changes/#version-0-12-5) * [Version 0.12.4](changes/#version-0-12-4) * [Version 0.12.3](changes/#version-0-12-3) * [Version 0.12.2](changes/#version-0-12-2) * [Version 0.12.1](changes/#version-0-12-1) * [Version 0.12](changes/#version-0-12) * [Version 0.11.1](changes/#version-0-11-1) * [Version 0.11](changes/#version-0-11) * [Version 0.10.1](changes/#version-0-10-1) * [Version 0.10](changes/#version-0-10) * [Version 0.9](changes/#version-0-9) * [Version 0.8.1](changes/#version-0-8-1) * [Version 0.8](changes/#version-0-8) * [Version 0.7.2](changes/#version-0-7-2) * [Version 0.7.1](changes/#version-0-7-1) * [Version 0.7](changes/#version-0-7) * [Version 0.6.1](changes/#version-0-6-1) * [Version 0.6](changes/#version-0-6) * [Version 0.5.2](changes/#version-0-5-2) * [Version 0.5.1](changes/#version-0-5-1) * [Version 0.5](changes/#version-0-5) * [Version 0.4](changes/#version-0-4) * [Version 0.3.1](changes/#version-0-3-1) * [Version 0.3](changes/#version-0-3) * [Version 0.2](changes/#version-0-2) * [Version 0.1](changes/#version-0-1) ### Project Links * [Donate](https://palletsprojects.com/donate) * [PyPI Releases](https://pypi.org/project/Flask/) * [Source Code](https://github.com/pallets/flask/) * [Issue Tracker](https://github.com/pallets/flask/issues/) * [Chat](https://discord.gg/pallets) ### Contents * [Welcome to Flask](#) * [User’s Guide](#user-s-guide) * [API Reference](#api-reference) * [Additional Notes](#additional-notes) ### Quick search --- # Index — Flask Documentation (3.1.x) ### Navigation * [index](# "General Index") * [modules](../py-modindex/ "Python Module Index") | * [Flask Documentation (3.1.x)](../) » * Index Index ===== [**\_**](#_) | [**A**](#A) | [**B**](#B) | [**C**](#C) | [**D**](#D) | [**E**](#E) | [**F**](#F) | [**G**](#G) | [**H**](#H) | [**I**](#I) | [**J**](#J) | [**K**](#K) | [**L**](#L) | [**M**](#M) | [**N**](#N) | [**O**](#O) | [**P**](#P) | [**Q**](#Q) | [**R**](#R) | [**S**](#S) | [**T**](#T) | [**U**](#U) | [**V**](#V) | [**W**](#W) | [**Y**](#Y) \_ -- * [\_AppCtxGlobals (class in flask.ctx)](../api/#flask.ctx._AppCtxGlobals) A - | | | | --- | --- | | * [abort() (in module flask)](../api/#flask.abort)

* [aborter (flask.Flask attribute)](../api/#flask.Flask.aborter)

* [aborter\_class (flask.Flask attribute)](../api/#flask.Flask.aborter_class)

* [accept\_charsets (flask.Request property)](../api/#flask.Request.accept_charsets)

* [accept\_encodings (flask.Request property)](../api/#flask.Request.accept_encodings)

* [accept\_languages (flask.Request property)](../api/#flask.Request.accept_languages)

* [accept\_mimetypes (flask.Request property)](../api/#flask.Request.accept_mimetypes)

* [accept\_ranges (flask.Response attribute)](../api/#flask.Response.accept_ranges)

* [access\_control\_allow\_credentials (flask.Response property)](../api/#flask.Response.access_control_allow_credentials)

* [access\_control\_allow\_headers (flask.Response attribute)](../api/#flask.Response.access_control_allow_headers)

* [access\_control\_allow\_methods (flask.Response attribute)](../api/#flask.Response.access_control_allow_methods)

* [access\_control\_allow\_origin (flask.Response attribute)](../api/#flask.Response.access_control_allow_origin)

* [access\_control\_expose\_headers (flask.Response attribute)](../api/#flask.Response.access_control_expose_headers)

* [access\_control\_max\_age (flask.Response attribute)](../api/#flask.Response.access_control_max_age)

* [access\_control\_request\_headers (flask.Request attribute)](../api/#flask.Request.access_control_request_headers)

* [access\_control\_request\_method (flask.Request attribute)](../api/#flask.Request.access_control_request_method)

* [access\_route (flask.Request property)](../api/#flask.Request.access_route)

* [accessed (flask.sessions.SecureCookieSession attribute)](../api/#flask.sessions.SecureCookieSession.accessed)
* [(flask.sessions.SessionMixin attribute)](../api/#flask.sessions.SessionMixin.accessed)

* [add\_app\_template\_filter() (flask.Blueprint method)](../api/#flask.Blueprint.add_app_template_filter)

* [add\_app\_template\_global() (flask.Blueprint method)](../api/#flask.Blueprint.add_app_template_global)

* [add\_app\_template\_test() (flask.Blueprint method)](../api/#flask.Blueprint.add_app_template_test)

* [add\_etag() (flask.Response method)](../api/#flask.Response.add_etag)

* [add\_template\_filter() (flask.Flask method)](../api/#flask.Flask.add_template_filter)

* [add\_template\_global() (flask.Flask method)](../api/#flask.Flask.add_template_global)

* [add\_template\_test() (flask.Flask method)](../api/#flask.Flask.add_template_test)

* [add\_url\_rule() (flask.Blueprint method)](../api/#flask.Blueprint.add_url_rule)
* [(flask.blueprints.BlueprintSetupState method)](../api/#flask.blueprints.BlueprintSetupState.add_url_rule)

* [(flask.Flask method)](../api/#flask.Flask.add_url_rule)

* [after\_app\_request() (flask.Blueprint method)](../api/#flask.Blueprint.after_app_request)

* [after\_request() (flask.Blueprint method)](../api/#flask.Blueprint.after_request)
* [(flask.Flask method)](../api/#flask.Flask.after_request) | * [after\_request\_funcs (flask.Blueprint attribute)](../api/#flask.Blueprint.after_request_funcs)
* [(flask.Flask attribute)](../api/#flask.Flask.after_request_funcs)

* [after\_this\_request() (in module flask)](../api/#flask.after_this_request)

* [age (flask.Response attribute)](../api/#flask.Response.age)

* [allow (flask.Response property)](../api/#flask.Response.allow)

* [app (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.app)

* [app\_context() (flask.Flask method)](../api/#flask.Flask.app_context)

* [app\_context\_processor() (flask.Blueprint method)](../api/#flask.Blueprint.app_context_processor)

* [app\_ctx\_globals\_class (flask.Flask attribute)](../api/#flask.Flask.app_ctx_globals_class)

* [app\_errorhandler() (flask.Blueprint method)](../api/#flask.Blueprint.app_errorhandler)

* [app\_import\_path (flask.cli.ScriptInfo attribute)](../api/#flask.cli.ScriptInfo.app_import_path)

* [app\_template\_filter() (flask.Blueprint method)](../api/#flask.Blueprint.app_template_filter)

* [app\_template\_global() (flask.Blueprint method)](../api/#flask.Blueprint.app_template_global)

* [app\_template\_test() (flask.Blueprint method)](../api/#flask.Blueprint.app_template_test)

* [app\_url\_defaults() (flask.Blueprint method)](../api/#flask.Blueprint.app_url_defaults)

* [app\_url\_value\_preprocessor() (flask.Blueprint method)](../api/#flask.Blueprint.app_url_value_preprocessor)

* [AppContext (class in flask.ctx)](../api/#flask.ctx.AppContext)

* [appcontext\_popped (in module flask)](../api/#flask.appcontext_popped)

* [appcontext\_pushed (in module flask)](../api/#flask.appcontext_pushed)

* [appcontext\_tearing\_down (in module flask)](../api/#flask.appcontext_tearing_down)

* [AppGroup (class in flask.cli)](../api/#flask.cli.AppGroup)

* [application() (flask.Request class method)](../api/#flask.Request.application)

* [APPLICATION\_ROOT (built-in variable)](../config/#APPLICATION_ROOT)

* [args (flask.Request property)](../api/#flask.Request.args)

* [as\_view() (flask.views.View class method)](../api/#flask.views.View.as_view)

* [async\_to\_sync() (flask.Flask method)](../api/#flask.Flask.async_to_sync)

* [authorization (flask.Request property)](../api/#flask.Request.authorization)

* [auto\_find\_instance\_path() (flask.Flask method)](../api/#flask.Flask.auto_find_instance_path)

* [autocorrect\_location\_header (flask.Response attribute)](../api/#flask.Response.autocorrect_location_header)

* [automatically\_set\_content\_length (flask.Response attribute)](../api/#flask.Response.automatically_set_content_length) | B - | | | | --- | --- | | * [base\_url (flask.Request property)](../api/#flask.Request.base_url)

* [before\_app\_request() (flask.Blueprint method)](../api/#flask.Blueprint.before_app_request)

* [before\_request() (flask.Blueprint method)](../api/#flask.Blueprint.before_request)
* [(flask.Flask method)](../api/#flask.Flask.before_request)

* [before\_request\_funcs (flask.Blueprint attribute)](../api/#flask.Blueprint.before_request_funcs)
* [(flask.Flask attribute)](../api/#flask.Flask.before_request_funcs) | * [Blueprint (class in flask)](../api/#flask.Blueprint)

* [blueprint (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.blueprint)
* [(flask.Request property)](../api/#flask.Request.blueprint)

* [blueprints (flask.Flask attribute)](../api/#flask.Flask.blueprints)
* [(flask.Request property)](../api/#flask.Request.blueprints)

* [BlueprintSetupState (class in flask.blueprints)](../api/#flask.blueprints.BlueprintSetupState) | C - | | | | --- | --- | | * [cache\_control (flask.Request property)](../api/#flask.Request.cache_control)
* [(flask.Response property)](../api/#flask.Response.cache_control)

* [calculate\_content\_length() (flask.Response method)](../api/#flask.Response.calculate_content_length)

* [call\_on\_close() (flask.Response method)](../api/#flask.Response.call_on_close)

* [check() (flask.json.tag.JSONTag method)](../api/#flask.json.tag.JSONTag.check)

* [clear() (flask.sessions.NullSession method)](../api/#flask.sessions.NullSession.clear)

* [cli (flask.Blueprint attribute)](../api/#flask.Blueprint.cli)
* [(flask.Flask attribute)](../api/#flask.Flask.cli)

* [close() (flask.Request method)](../api/#flask.Request.close)
* [(flask.Response method)](../api/#flask.Response.close)

* [command() (flask.cli.AppGroup method)](../api/#flask.cli.AppGroup.command)

* [compact (flask.json.provider.DefaultJSONProvider attribute)](../api/#flask.json.provider.DefaultJSONProvider.compact)

* [Config (class in flask)](../api/#flask.Config)

* [config (flask.Flask attribute)](../api/#flask.Flask.config)

* [config\_class (flask.Flask attribute)](../api/#flask.Flask.config_class)

* [content\_encoding (flask.Request attribute)](../api/#flask.Request.content_encoding)
* [(flask.Response attribute)](../api/#flask.Response.content_encoding)

* [content\_language (flask.Response property)](../api/#flask.Response.content_language)

* [content\_length (flask.Request property)](../api/#flask.Request.content_length)
* [(flask.Response attribute)](../api/#flask.Response.content_length) | * [content\_location (flask.Response attribute)](../api/#flask.Response.content_location)

* [content\_md5 (flask.Request attribute)](../api/#flask.Request.content_md5)
* [(flask.Response attribute)](../api/#flask.Response.content_md5)

* [content\_range (flask.Response property)](../api/#flask.Response.content_range)

* [content\_security\_policy (flask.Response property)](../api/#flask.Response.content_security_policy)

* [content\_security\_policy\_report\_only (flask.Response property)](../api/#flask.Response.content_security_policy_report_only)

* [content\_type (flask.Request attribute)](../api/#flask.Request.content_type)
* [(flask.Response attribute)](../api/#flask.Response.content_type)

* [context\_processor() (flask.Blueprint method)](../api/#flask.Blueprint.context_processor)
* [(flask.Flask method)](../api/#flask.Flask.context_processor)

* [cookies (flask.Request property)](../api/#flask.Request.cookies)

* [copy() (flask.ctx.RequestContext method)](../api/#flask.ctx.RequestContext.copy)

* [copy\_current\_request\_context() (in module flask)](../api/#flask.copy_current_request_context)

* [create\_app (flask.cli.ScriptInfo attribute)](../api/#flask.cli.ScriptInfo.create_app)

* [create\_global\_jinja\_loader() (flask.Flask method)](../api/#flask.Flask.create_global_jinja_loader)

* [create\_jinja\_environment() (flask.Flask method)](../api/#flask.Flask.create_jinja_environment)

* [create\_url\_adapter() (flask.Flask method)](../api/#flask.Flask.create_url_adapter)

* [cross\_origin\_embedder\_policy (flask.Response attribute)](../api/#flask.Response.cross_origin_embedder_policy)

* [cross\_origin\_opener\_policy (flask.Response attribute)](../api/#flask.Response.cross_origin_opener_policy)

* [current\_app (in module flask)](../api/#flask.current_app) | D - | | | | --- | --- | | * [data (flask.cli.ScriptInfo attribute)](../api/#flask.cli.ScriptInfo.data)
* [(flask.Request property)](../api/#flask.Request.data)

* [(flask.Response property)](../api/#flask.Response.data)

* [date (flask.Request attribute)](../api/#flask.Request.date)
* [(flask.Response attribute)](../api/#flask.Response.date)

* [DEBUG (built-in variable)](../config/#DEBUG)

* [debug (flask.Flask property)](../api/#flask.Flask.debug)

* [decorators (flask.views.View attribute)](../api/#flask.views.View.decorators)

* [default() (flask.json.provider.DefaultJSONProvider static method)](../api/#flask.json.provider.DefaultJSONProvider.default)

* [default\_mimetype (flask.Response attribute)](../api/#flask.Response.default_mimetype)

* [default\_status (flask.Response attribute)](../api/#flask.Response.default_status)

* [default\_tags (flask.json.tag.TaggedJSONSerializer attribute)](../api/#flask.json.tag.TaggedJSONSerializer.default_tags)

* [DefaultJSONProvider (class in flask.json.provider)](../api/#flask.json.provider.DefaultJSONProvider)

* [delete() (flask.Blueprint method)](../api/#flask.Blueprint.delete)
* [(flask.Flask method)](../api/#flask.Flask.delete) | * [delete\_cookie() (flask.Response method)](../api/#flask.Response.delete_cookie)

* [dict\_storage\_class (flask.Request attribute)](../api/#flask.Request.dict_storage_class)

* [digest\_method() (flask.sessions.SecureCookieSessionInterface static method)](../api/#flask.sessions.SecureCookieSessionInterface.digest_method)

* [direct\_passthrough (flask.Response attribute)](../api/#flask.Response.direct_passthrough)

* [dispatch\_request() (flask.Flask method)](../api/#flask.Flask.dispatch_request)
* [(flask.views.MethodView method)](../api/#flask.views.MethodView.dispatch_request)

* [(flask.views.View method)](../api/#flask.views.View.dispatch_request)

* [do\_teardown\_appcontext() (flask.Flask method)](../api/#flask.Flask.do_teardown_appcontext)

* [do\_teardown\_request() (flask.Flask method)](../api/#flask.Flask.do_teardown_request)

* [dump() (flask.json.provider.JSONProvider method)](../api/#flask.json.provider.JSONProvider.dump)
* [(in module flask.json)](../api/#flask.json.dump)

* [dumps() (flask.json.provider.DefaultJSONProvider method)](../api/#flask.json.provider.DefaultJSONProvider.dumps)
* [(flask.json.provider.JSONProvider method)](../api/#flask.json.provider.JSONProvider.dumps)

* [(flask.json.tag.TaggedJSONSerializer method)](../api/#flask.json.tag.TaggedJSONSerializer.dumps)

* [(in module flask.json)](../api/#flask.json.dumps) | E - | | | | --- | --- | | * [endpoint (flask.Request property)](../api/#flask.Request.endpoint)

* [endpoint() (flask.Blueprint method)](../api/#flask.Blueprint.endpoint)
* [(flask.Flask method)](../api/#flask.Flask.endpoint)

* [ensure\_ascii (flask.json.provider.DefaultJSONProvider attribute)](../api/#flask.json.provider.DefaultJSONProvider.ensure_ascii)

* [ensure\_sync() (flask.Flask method)](../api/#flask.Flask.ensure_sync)

* [environ (flask.Request attribute)](../api/#flask.Request.environ)

* environment variable
* [FLASK\_DEBUG](../api/#index-0)

* [FLASK\_ENV](../config/#index-0)

* [YOURAPPLICATION\_SETTINGS](../config/#index-1) | * [error\_handler\_spec (flask.Blueprint attribute)](../api/#flask.Blueprint.error_handler_spec)
* [(flask.Flask attribute)](../api/#flask.Flask.error_handler_spec)

* [errorhandler() (flask.Blueprint method)](../api/#flask.Blueprint.errorhandler)
* [(flask.Flask method)](../api/#flask.Flask.errorhandler)

* [expires (flask.Response attribute)](../api/#flask.Response.expires)

* [EXPLAIN\_TEMPLATE\_LOADING (built-in variable)](../config/#EXPLAIN_TEMPLATE_LOADING)

* [extensions (flask.Flask attribute)](../api/#flask.Flask.extensions) | F - | | | | --- | --- | | * [files (flask.Request property)](../api/#flask.Request.files)

* [first\_registration (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.first_registration)

* [flash() (in module flask)](../api/#flask.flash)

* flask
* [module](../api/#module-flask)

* [Flask (class in flask)](../api/#flask.Flask)

* [flask.globals.app\_ctx (in module flask)](../api/#flask.flask.globals.app_ctx)

* [flask.globals.request\_ctx (in module flask)](../api/#flask.flask.globals.request_ctx)

* flask.json
* [module](../api/#module-flask.json)

* flask.json.tag
* [module](../api/#module-flask.json.tag)

* [FLASK\_DEBUG](../api/#index-0)

* [FLASK\_ENV](../config/#index-0)

* [FlaskClient (class in flask.testing)](../api/#flask.testing.FlaskClient) | * [FlaskCliRunner (class in flask.testing)](../api/#flask.testing.FlaskCliRunner)

* [FlaskGroup (class in flask.cli)](../api/#flask.cli.FlaskGroup)

* [force\_type() (flask.Response class method)](../api/#flask.Response.force_type)

* [form (flask.Request property)](../api/#flask.Request.form)

* [form\_data\_parser\_class (flask.Request attribute)](../api/#flask.Request.form_data_parser_class)

* [freeze() (flask.Response method)](../api/#flask.Response.freeze)

* [from\_app() (flask.Response class method)](../api/#flask.Response.from_app)

* [from\_envvar() (flask.Config method)](../api/#flask.Config.from_envvar)

* [from\_file() (flask.Config method)](../api/#flask.Config.from_file)

* [from\_mapping() (flask.Config method)](../api/#flask.Config.from_mapping)

* [from\_object() (flask.Config method)](../api/#flask.Config.from_object)

* [from\_prefixed\_env() (flask.Config method)](../api/#flask.Config.from_prefixed_env)

* [from\_pyfile() (flask.Config method)](../api/#flask.Config.from_pyfile)

* [from\_values() (flask.Request class method)](../api/#flask.Request.from_values)

* [full\_dispatch\_request() (flask.Flask method)](../api/#flask.Flask.full_dispatch_request)

* [full\_path (flask.Request property)](../api/#flask.Request.full_path) | G - | | | | --- | --- | | * [g (in module flask)](../api/#flask.g)

* [get() (flask.Blueprint method)](../api/#flask.Blueprint.get)
* [(flask.ctx.\_AppCtxGlobals method)](../api/#flask.ctx._AppCtxGlobals.get)

* [(flask.Flask method)](../api/#flask.Flask.get)

* [(flask.sessions.SecureCookieSession method)](../api/#flask.sessions.SecureCookieSession.get)

* [get\_app\_iter() (flask.Response method)](../api/#flask.Response.get_app_iter)

* [get\_command() (flask.cli.FlaskGroup method)](../api/#flask.cli.FlaskGroup.get_command)

* [get\_cookie\_domain() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_domain)

* [get\_cookie\_httponly() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_httponly)

* [get\_cookie\_name() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_name)

* [get\_cookie\_partitioned() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_partitioned)

* [get\_cookie\_path() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_path)

* [get\_cookie\_samesite() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_samesite)

* [get\_cookie\_secure() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_cookie_secure) | * [get\_data() (flask.Request method)](../api/#flask.Request.get_data)
* [(flask.Response method)](../api/#flask.Response.get_data)

* [get\_etag() (flask.Response method)](../api/#flask.Response.get_etag)

* [get\_expiration\_time() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.get_expiration_time)

* [get\_flashed\_messages() (in module flask)](../api/#flask.get_flashed_messages)

* [get\_json() (flask.Request method)](../api/#flask.Request.get_json)
* [(flask.Response method)](../api/#flask.Response.get_json)

* [get\_namespace() (flask.Config method)](../api/#flask.Config.get_namespace)

* [get\_send\_file\_max\_age() (flask.Blueprint method)](../api/#flask.Blueprint.get_send_file_max_age)
* [(flask.Flask method)](../api/#flask.Flask.get_send_file_max_age)

* [get\_template\_attribute() (in module flask)](../api/#flask.get_template_attribute)

* [get\_wsgi\_headers() (flask.Response method)](../api/#flask.Response.get_wsgi_headers)

* [get\_wsgi\_response() (flask.Response method)](../api/#flask.Response.get_wsgi_response)

* [got\_request\_exception (in module flask)](../api/#flask.got_request_exception)

* [group() (flask.cli.AppGroup method)](../api/#flask.cli.AppGroup.group) | H - | | | | --- | --- | | * [handle\_exception() (flask.Flask method)](../api/#flask.Flask.handle_exception)

* [handle\_http\_exception() (flask.Flask method)](../api/#flask.Flask.handle_http_exception)

* [handle\_url\_build\_error() (flask.Flask method)](../api/#flask.Flask.handle_url_build_error)

* [handle\_user\_exception() (flask.Flask method)](../api/#flask.Flask.handle_user_exception)

* [has\_app\_context() (in module flask)](../api/#flask.has_app_context) | * [has\_request\_context() (in module flask)](../api/#flask.has_request_context)

* [has\_static\_folder (flask.Blueprint property)](../api/#flask.Blueprint.has_static_folder)
* [(flask.Flask property)](../api/#flask.Flask.has_static_folder)

* [headers (flask.Request attribute)](../api/#flask.Request.headers)

* [host (flask.Request property)](../api/#flask.Request.host)

* [host\_url (flask.Request property)](../api/#flask.Request.host_url) | I - | | | | --- | --- | | * [if\_match (flask.Request property)](../api/#flask.Request.if_match)

* [if\_modified\_since (flask.Request property)](../api/#flask.Request.if_modified_since)

* [if\_none\_match (flask.Request property)](../api/#flask.Request.if_none_match)

* [if\_range (flask.Request property)](../api/#flask.Request.if_range)

* [if\_unmodified\_since (flask.Request property)](../api/#flask.Request.if_unmodified_since)

* [implicit\_sequence\_conversion (flask.Response attribute)](../api/#flask.Response.implicit_sequence_conversion)

* [import\_name (flask.Blueprint attribute)](../api/#flask.Blueprint.import_name)
* [(flask.Flask attribute)](../api/#flask.Flask.import_name)

* [init\_every\_request (flask.views.View attribute)](../api/#flask.views.View.init_every_request)

* [inject\_url\_defaults() (flask.Flask method)](../api/#flask.Flask.inject_url_defaults)

* [input\_stream (flask.Request attribute)](../api/#flask.Request.input_stream)

* [instance\_path (flask.Flask attribute)](../api/#flask.Flask.instance_path) | * [invoke() (flask.testing.FlaskCliRunner method)](../api/#flask.testing.FlaskCliRunner.invoke)

* [is\_json (flask.Request property)](../api/#flask.Request.is_json)
* [(flask.Response property)](../api/#flask.Response.is_json)

* [is\_multiprocess (flask.Request attribute)](../api/#flask.Request.is_multiprocess)

* [is\_multithread (flask.Request attribute)](../api/#flask.Request.is_multithread)

* [is\_null\_session() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.is_null_session)

* [is\_run\_once (flask.Request attribute)](../api/#flask.Request.is_run_once)

* [is\_secure (flask.Request property)](../api/#flask.Request.is_secure)

* [is\_sequence (flask.Response property)](../api/#flask.Response.is_sequence)

* [is\_streamed (flask.Response property)](../api/#flask.Response.is_streamed)

* [iter\_blueprints() (flask.Flask method)](../api/#flask.Flask.iter_blueprints)

* [iter\_encoded() (flask.Response method)](../api/#flask.Response.iter_encoded) | J - | | | | --- | --- | | * [jinja\_env (flask.Flask property)](../api/#flask.Flask.jinja_env)

* [jinja\_environment (flask.Flask attribute)](../api/#flask.Flask.jinja_environment)

* [jinja\_loader (flask.Blueprint property)](../api/#flask.Blueprint.jinja_loader)
* [(flask.Flask property)](../api/#flask.Flask.jinja_loader)

* [jinja\_options (flask.Flask attribute)](../api/#flask.Flask.jinja_options)

* [json (flask.Flask attribute)](../api/#flask.Flask.json)
* [(flask.Request property)](../api/#flask.Request.json)

* [(flask.Response property)](../api/#flask.Response.json) | * [json\_provider\_class (flask.Flask attribute)](../api/#flask.Flask.json_provider_class)

* [jsonify() (in module flask.json)](../api/#flask.json.jsonify)

* [JSONProvider (class in flask.json.provider)](../api/#flask.json.provider.JSONProvider)

* [JSONTag (class in flask.json.tag)](../api/#flask.json.tag.JSONTag) | K - | | | | --- | --- | | * [key (flask.json.tag.JSONTag attribute)](../api/#flask.json.tag.JSONTag.key) | * [key\_derivation (flask.sessions.SecureCookieSessionInterface attribute)](../api/#flask.sessions.SecureCookieSessionInterface.key_derivation) | L - | | | | --- | --- | | * [last\_modified (flask.Response attribute)](../api/#flask.Response.last_modified)

* [list\_commands() (flask.cli.FlaskGroup method)](../api/#flask.cli.FlaskGroup.list_commands)

* [list\_storage\_class (flask.Request attribute)](../api/#flask.Request.list_storage_class)

* [load() (flask.json.provider.JSONProvider method)](../api/#flask.json.provider.JSONProvider.load)
* [(in module flask.json)](../api/#flask.json.load)

* [load\_app() (flask.cli.ScriptInfo method)](../api/#flask.cli.ScriptInfo.load_app)

* [load\_dotenv() (in module flask.cli)](../api/#flask.cli.load_dotenv) | * [load\_dotenv\_defaults (flask.cli.ScriptInfo attribute)](../api/#flask.cli.ScriptInfo.load_dotenv_defaults)

* [loads() (flask.json.provider.DefaultJSONProvider method)](../api/#flask.json.provider.DefaultJSONProvider.loads)
* [(flask.json.provider.JSONProvider method)](../api/#flask.json.provider.JSONProvider.loads)

* [(flask.json.tag.TaggedJSONSerializer method)](../api/#flask.json.tag.TaggedJSONSerializer.loads)

* [(in module flask.json)](../api/#flask.json.loads)

* [location (flask.Response attribute)](../api/#flask.Response.location)

* [log\_exception() (flask.Flask method)](../api/#flask.Flask.log_exception)

* [logger (flask.Flask property)](../api/#flask.Flask.logger) | M - | | | | --- | --- | | * [make\_aborter() (flask.Flask method)](../api/#flask.Flask.make_aborter)

* [make\_conditional() (flask.Response method)](../api/#flask.Response.make_conditional)

* [make\_config() (flask.Flask method)](../api/#flask.Flask.make_config)

* [make\_context() (flask.cli.FlaskGroup method)](../api/#flask.cli.FlaskGroup.make_context)

* [make\_default\_options\_response() (flask.Flask method)](../api/#flask.Flask.make_default_options_response)

* [make\_form\_data\_parser() (flask.Request method)](../api/#flask.Request.make_form_data_parser)

* [make\_null\_session() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.make_null_session)

* [make\_response() (flask.Flask method)](../api/#flask.Flask.make_response)
* [(in module flask)](../api/#flask.make_response)

* [make\_sequence() (flask.Response method)](../api/#flask.Response.make_sequence)

* [make\_setup\_state() (flask.Blueprint method)](../api/#flask.Blueprint.make_setup_state)

* [make\_shell\_context() (flask.Flask method)](../api/#flask.Flask.make_shell_context)

* [match\_request() (flask.ctx.RequestContext method)](../api/#flask.ctx.RequestContext.match_request)

* [MAX\_CONTENT\_LENGTH (built-in variable)](../config/#MAX_CONTENT_LENGTH)

* [max\_content\_length (flask.Request property)](../api/#flask.Request.max_content_length)

* [MAX\_COOKIE\_SIZE (built-in variable)](../config/#MAX_COOKIE_SIZE)

* [max\_cookie\_size (flask.Response property)](../api/#flask.Response.max_cookie_size)

* [MAX\_FORM\_MEMORY\_SIZE (built-in variable)](../config/#MAX_FORM_MEMORY_SIZE)

* [max\_form\_memory\_size (flask.Request property)](../api/#flask.Request.max_form_memory_size) | * [MAX\_FORM\_PARTS (built-in variable)](../config/#MAX_FORM_PARTS)

* [max\_form\_parts (flask.Request property)](../api/#flask.Request.max_form_parts)

* [max\_forwards (flask.Request attribute)](../api/#flask.Request.max_forwards)

* [message\_flashed (in module flask)](../api/#flask.message_flashed)

* [method (flask.Request attribute)](../api/#flask.Request.method)

* [methods (flask.views.View attribute)](../api/#flask.views.View.methods)

* [MethodView (class in flask.views)](../api/#flask.views.MethodView)

* [mimetype (flask.json.provider.DefaultJSONProvider attribute)](../api/#flask.json.provider.DefaultJSONProvider.mimetype)
* [(flask.Request property)](../api/#flask.Request.mimetype)

* [(flask.Response property)](../api/#flask.Response.mimetype)

* [mimetype\_params (flask.Request property)](../api/#flask.Request.mimetype_params)
* [(flask.Response property)](../api/#flask.Response.mimetype_params)

* [modified (flask.session attribute)](../api/#flask.session.modified)
* [(flask.sessions.SecureCookieSession attribute)](../api/#flask.sessions.SecureCookieSession.modified)

* [(flask.sessions.SessionMixin attribute)](../api/#flask.sessions.SessionMixin.modified)

* module
* [flask](../api/#module-flask)

* [flask.json](../api/#module-flask.json)

* [flask.json.tag](../api/#module-flask.json.tag) | N - | | | | --- | --- | | * [name (flask.Flask property)](../api/#flask.Flask.name)

* [new (flask.session attribute)](../api/#flask.session.new) | * [null\_session\_class (flask.sessions.SessionInterface attribute)](../api/#flask.sessions.SessionInterface.null_session_class)

* [NullSession (class in flask.sessions)](../api/#flask.sessions.NullSession) | O - | | | | --- | --- | | * [on\_json\_loading\_failed() (flask.Request method)](../api/#flask.Request.on_json_loading_failed)

* [open() (flask.testing.FlaskClient method)](../api/#flask.testing.FlaskClient.open)

* [open\_instance\_resource() (flask.Flask method)](../api/#flask.Flask.open_instance_resource)

* [open\_resource() (flask.Blueprint method)](../api/#flask.Blueprint.open_resource)
* [(flask.Flask method)](../api/#flask.Flask.open_resource) | * [open\_session() (flask.sessions.SecureCookieSessionInterface method)](../api/#flask.sessions.SecureCookieSessionInterface.open_session)
* [(flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.open_session)

* [options (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.options)

* [origin (flask.Request attribute)](../api/#flask.Request.origin) | P - | | | | --- | --- | | * [parameter\_storage\_class (flask.Request attribute)](../api/#flask.Request.parameter_storage_class)

* [parse\_args() (flask.cli.FlaskGroup method)](../api/#flask.cli.FlaskGroup.parse_args)

* [pass\_script\_info() (in module flask.cli)](../api/#flask.cli.pass_script_info)

* [patch() (flask.Blueprint method)](../api/#flask.Blueprint.patch)
* [(flask.Flask method)](../api/#flask.Flask.patch)

* [path (flask.Request attribute)](../api/#flask.Request.path)

* [permanent (flask.session attribute)](../api/#flask.session.permanent)
* [(flask.sessions.SessionMixin property)](../api/#flask.sessions.SessionMixin.permanent)

* [PERMANENT\_SESSION\_LIFETIME (built-in variable)](../config/#PERMANENT_SESSION_LIFETIME)

* [permanent\_session\_lifetime (flask.Flask attribute)](../api/#flask.Flask.permanent_session_lifetime)

* [pickle\_based (flask.sessions.SessionInterface attribute)](../api/#flask.sessions.SessionInterface.pickle_based)

* [pop() (flask.ctx.\_AppCtxGlobals method)](../api/#flask.ctx._AppCtxGlobals.pop)
* [(flask.ctx.AppContext method)](../api/#flask.ctx.AppContext.pop)

* [(flask.ctx.RequestContext method)](../api/#flask.ctx.RequestContext.pop)

* [(flask.sessions.NullSession method)](../api/#flask.sessions.NullSession.pop)

* [popitem() (flask.sessions.NullSession method)](../api/#flask.sessions.NullSession.popitem) | * [post() (flask.Blueprint method)](../api/#flask.Blueprint.post)
* [(flask.Flask method)](../api/#flask.Flask.post)

* [pragma (flask.Request property)](../api/#flask.Request.pragma)

* [PREFERRED\_URL\_SCHEME (built-in variable)](../config/#PREFERRED_URL_SCHEME)

* [preprocess\_request() (flask.Flask method)](../api/#flask.Flask.preprocess_request)

* [process\_response() (flask.Flask method)](../api/#flask.Flask.process_response)

* [PROPAGATE\_EXCEPTIONS (built-in variable)](../config/#PROPAGATE_EXCEPTIONS)

* [PROVIDE\_AUTOMATIC\_OPTIONS (built-in variable)](../config/#PROVIDE_AUTOMATIC_OPTIONS)

* [provide\_automatic\_options (flask.views.View attribute)](../api/#flask.views.View.provide_automatic_options)

* [push() (flask.ctx.AppContext method)](../api/#flask.ctx.AppContext.push)

* [put() (flask.Blueprint method)](../api/#flask.Blueprint.put)
* [(flask.Flask method)](../api/#flask.Flask.put)

* Python Enhancement Proposals
* [PEP 302](../changes/#index-5)

* [PEP 3333](../changes/#index-2)
, [\[1\]](../lifecycle/#index-0)

* [PEP 451](../changes/#index-1)

* [PEP 519](../changes/#index-0) | Q - * [query\_string (flask.Request attribute)](../api/#flask.Request.query_string) R - | | | | --- | --- | | * [range (flask.Request property)](../api/#flask.Request.range)

* [record() (flask.Blueprint method)](../api/#flask.Blueprint.record)

* [record\_once() (flask.Blueprint method)](../api/#flask.Blueprint.record_once)

* [redirect() (flask.Flask method)](../api/#flask.Flask.redirect)
* [(in module flask)](../api/#flask.redirect)

* [referrer (flask.Request attribute)](../api/#flask.Request.referrer)

* [register() (flask.Blueprint method)](../api/#flask.Blueprint.register)
* [(flask.json.tag.TaggedJSONSerializer method)](../api/#flask.json.tag.TaggedJSONSerializer.register)

* [register\_blueprint() (flask.Blueprint method)](../api/#flask.Blueprint.register_blueprint)
* [(flask.Flask method)](../api/#flask.Flask.register_blueprint)

* [register\_error\_handler() (flask.Blueprint method)](../api/#flask.Blueprint.register_error_handler)
* [(flask.Flask method)](../api/#flask.Flask.register_error_handler)

* [remote\_addr (flask.Request attribute)](../api/#flask.Request.remote_addr)

* [remote\_user (flask.Request attribute)](../api/#flask.Request.remote_user)

* [render\_template() (in module flask)](../api/#flask.render_template)

* [render\_template\_string() (in module flask)](../api/#flask.render_template_string)

* [Request (class in flask)](../api/#flask.Request)

* [request (in module flask)](../api/#flask.request)

* [request\_class (flask.Flask attribute)](../api/#flask.Flask.request_class)

* [request\_context() (flask.Flask method)](../api/#flask.Flask.request_context)

* [request\_finished (in module flask)](../api/#flask.request_finished) | * [request\_started (in module flask)](../api/#flask.request_started)

* [request\_tearing\_down (in module flask)](../api/#flask.request_tearing_down)

* [RequestContext (class in flask.ctx)](../api/#flask.ctx.RequestContext)

* [Response (class in flask)](../api/#flask.Response)

* [response (flask.Response attribute)](../api/#flask.Response.response)

* [response() (flask.json.provider.DefaultJSONProvider method)](../api/#flask.json.provider.DefaultJSONProvider.response)
* [(flask.json.provider.JSONProvider method)](../api/#flask.json.provider.JSONProvider.response)

* [response\_class (flask.Flask attribute)](../api/#flask.Flask.response_class)

* [retry\_after (flask.Response property)](../api/#flask.Response.retry_after)

* RFC
* [RFC 2231](../api/#index-1)

* [RFC 822](../api/#index-2)

* [RFC 8259](../changes/#index-3)
, [\[1\]](../changes/#index-4)

* [root\_path (flask.Blueprint attribute)](../api/#flask.Blueprint.root_path)
* [(flask.Flask attribute)](../api/#flask.Flask.root_path)

* [(flask.Request attribute)](../api/#flask.Request.root_path)

* [root\_url (flask.Request property)](../api/#flask.Request.root_url)

* [route() (flask.Blueprint method)](../api/#flask.Blueprint.route)
* [(flask.Flask method)](../api/#flask.Flask.route)

* [routing\_exception (flask.Request attribute)](../api/#flask.Request.routing_exception)

* [run() (flask.Flask method)](../api/#flask.Flask.run)

* [run\_command (in module flask.cli)](../api/#flask.cli.run_command) | S - | | | | --- | --- | | * [salt (flask.sessions.SecureCookieSessionInterface attribute)](../api/#flask.sessions.SecureCookieSessionInterface.salt)

* [save\_session() (flask.sessions.SecureCookieSessionInterface method)](../api/#flask.sessions.SecureCookieSessionInterface.save_session)
* [(flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.save_session)

* [scheme (flask.Request attribute)](../api/#flask.Request.scheme)

* [script\_root (flask.Request property)](../api/#flask.Request.script_root)

* [ScriptInfo (class in flask.cli)](../api/#flask.cli.ScriptInfo)

* [SECRET\_KEY (built-in variable)](../config/#SECRET_KEY)

* [secret\_key (flask.Flask attribute)](../api/#flask.Flask.secret_key)

* [SECRET\_KEY\_FALLBACKS (built-in variable)](../config/#SECRET_KEY_FALLBACKS)

* [SecureCookieSession (class in flask.sessions)](../api/#flask.sessions.SecureCookieSession)

* [SecureCookieSessionInterface (class in flask.sessions)](../api/#flask.sessions.SecureCookieSessionInterface)

* [select\_jinja\_autoescape() (flask.Flask method)](../api/#flask.Flask.select_jinja_autoescape)

* [send\_file() (in module flask)](../api/#flask.send_file)

* [SEND\_FILE\_MAX\_AGE\_DEFAULT (built-in variable)](../config/#SEND_FILE_MAX_AGE_DEFAULT)

* [send\_from\_directory() (in module flask)](../api/#flask.send_from_directory)

* [send\_static\_file() (flask.Blueprint method)](../api/#flask.Blueprint.send_static_file)
* [(flask.Flask method)](../api/#flask.Flask.send_static_file)

* [serializer (flask.sessions.SecureCookieSessionInterface attribute)](../api/#flask.sessions.SecureCookieSessionInterface.serializer)

* [server (flask.Request attribute)](../api/#flask.Request.server)

* [SERVER\_NAME (built-in variable)](../config/#SERVER_NAME)

* [session (class in flask)](../api/#flask.session)

* [session\_class (flask.sessions.SecureCookieSessionInterface attribute)](../api/#flask.sessions.SecureCookieSessionInterface.session_class)

* [SESSION\_COOKIE\_DOMAIN (built-in variable)](../config/#SESSION_COOKIE_DOMAIN)

* [SESSION\_COOKIE\_HTTPONLY (built-in variable)](../config/#SESSION_COOKIE_HTTPONLY)

* [SESSION\_COOKIE\_NAME (built-in variable)](../config/#SESSION_COOKIE_NAME)

* [SESSION\_COOKIE\_PARTITIONED (built-in variable)](../config/#SESSION_COOKIE_PARTITIONED)

* [SESSION\_COOKIE\_PATH (built-in variable)](../config/#SESSION_COOKIE_PATH)

* [SESSION\_COOKIE\_SAMESITE (built-in variable)](../config/#SESSION_COOKIE_SAMESITE)

* [SESSION\_COOKIE\_SECURE (built-in variable)](../config/#SESSION_COOKIE_SECURE) | * [session\_interface (flask.Flask attribute)](../api/#flask.Flask.session_interface)

* [SESSION\_REFRESH\_EACH\_REQUEST (built-in variable)](../config/#SESSION_REFRESH_EACH_REQUEST)

* [session\_transaction() (flask.testing.FlaskClient method)](../api/#flask.testing.FlaskClient.session_transaction)

* [SessionInterface (class in flask.sessions)](../api/#flask.sessions.SessionInterface)

* [SessionMixin (class in flask.sessions)](../api/#flask.sessions.SessionMixin)

* [set\_cookie() (flask.Response method)](../api/#flask.Response.set_cookie)

* [set\_data() (flask.Response method)](../api/#flask.Response.set_data)

* [set\_etag() (flask.Response method)](../api/#flask.Response.set_etag)

* [setdefault() (flask.ctx.\_AppCtxGlobals method)](../api/#flask.ctx._AppCtxGlobals.setdefault)
* [(flask.sessions.NullSession method)](../api/#flask.sessions.NullSession.setdefault)

* [(flask.sessions.SecureCookieSession method)](../api/#flask.sessions.SecureCookieSession.setdefault)

* [shallow (flask.Request attribute)](../api/#flask.Request.shallow)

* [shell\_command (in module flask.cli)](../api/#flask.cli.shell_command)

* [shell\_context\_processor() (flask.Flask method)](../api/#flask.Flask.shell_context_processor)

* [shell\_context\_processors (flask.Flask attribute)](../api/#flask.Flask.shell_context_processors)

* [should\_ignore\_error() (flask.Flask method)](../api/#flask.Flask.should_ignore_error)

* [should\_set\_cookie() (flask.sessions.SessionInterface method)](../api/#flask.sessions.SessionInterface.should_set_cookie)

* [sort\_keys (flask.json.provider.DefaultJSONProvider attribute)](../api/#flask.json.provider.DefaultJSONProvider.sort_keys)

* [static\_folder (flask.Blueprint property)](../api/#flask.Blueprint.static_folder)
* [(flask.Flask property)](../api/#flask.Flask.static_folder)

* [static\_url\_path (flask.Blueprint property)](../api/#flask.Blueprint.static_url_path)
* [(flask.Flask property)](../api/#flask.Flask.static_url_path)

* [status (flask.Response property)](../api/#flask.Response.status)

* [status\_code (flask.Response property)](../api/#flask.Response.status_code)

* [stream (flask.Request property)](../api/#flask.Request.stream)
* [(flask.Response property)](../api/#flask.Response.stream)

* [stream\_template() (in module flask)](../api/#flask.stream_template)

* [stream\_template\_string() (in module flask)](../api/#flask.stream_template_string)

* [stream\_with\_context() (in module flask)](../api/#flask.stream_with_context)

* [subdomain (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.subdomain) | T - | | | | --- | --- | | * [tag() (flask.json.tag.JSONTag method)](../api/#flask.json.tag.JSONTag.tag)
* [(flask.json.tag.TaggedJSONSerializer method)](../api/#flask.json.tag.TaggedJSONSerializer.tag)

* [TaggedJSONSerializer (class in flask.json.tag)](../api/#flask.json.tag.TaggedJSONSerializer)

* [teardown\_app\_request() (flask.Blueprint method)](../api/#flask.Blueprint.teardown_app_request)

* [teardown\_appcontext() (flask.Flask method)](../api/#flask.Flask.teardown_appcontext)

* [teardown\_appcontext\_funcs (flask.Flask attribute)](../api/#flask.Flask.teardown_appcontext_funcs)

* [teardown\_request() (flask.Blueprint method)](../api/#flask.Blueprint.teardown_request)
* [(flask.Flask method)](../api/#flask.Flask.teardown_request)

* [teardown\_request\_funcs (flask.Blueprint attribute)](../api/#flask.Blueprint.teardown_request_funcs)
* [(flask.Flask attribute)](../api/#flask.Flask.teardown_request_funcs)

* [template\_context\_processors (flask.Blueprint attribute)](../api/#flask.Blueprint.template_context_processors)
* [(flask.Flask attribute)](../api/#flask.Flask.template_context_processors)

* [template\_filter() (flask.Flask method)](../api/#flask.Flask.template_filter)

* [template\_folder (flask.Blueprint attribute)](../api/#flask.Blueprint.template_folder)
* [(flask.Flask attribute)](../api/#flask.Flask.template_folder)

* [template\_global() (flask.Flask method)](../api/#flask.Flask.template_global) | * [template\_rendered (in module flask)](../api/#flask.template_rendered)

* [template\_test() (flask.Flask method)](../api/#flask.Flask.template_test)

* [TEMPLATES\_AUTO\_RELOAD (built-in variable)](../config/#TEMPLATES_AUTO_RELOAD)

* [test\_cli\_runner() (flask.Flask method)](../api/#flask.Flask.test_cli_runner)

* [test\_cli\_runner\_class (flask.Flask attribute)](../api/#flask.Flask.test_cli_runner_class)

* [test\_client() (flask.Flask method)](../api/#flask.Flask.test_client)

* [test\_client\_class (flask.Flask attribute)](../api/#flask.Flask.test_client_class)

* [test\_request\_context() (flask.Flask method)](../api/#flask.Flask.test_request_context)

* [TESTING (built-in variable)](../config/#TESTING)

* [testing (flask.Flask attribute)](../api/#flask.Flask.testing)

* [to\_json() (flask.json.tag.JSONTag method)](../api/#flask.json.tag.JSONTag.to_json)

* [to\_python() (flask.json.tag.JSONTag method)](../api/#flask.json.tag.JSONTag.to_python)

* [TRAP\_BAD\_REQUEST\_ERRORS (built-in variable)](../config/#TRAP_BAD_REQUEST_ERRORS)

* [trap\_http\_exception() (flask.Flask method)](../api/#flask.Flask.trap_http_exception)

* [TRAP\_HTTP\_EXCEPTIONS (built-in variable)](../config/#TRAP_HTTP_EXCEPTIONS)

* [TRUSTED\_HOSTS (built-in variable)](../config/#TRUSTED_HOSTS)

* [trusted\_hosts (flask.Request attribute)](../api/#flask.Request.trusted_hosts) | U - | | | | --- | --- | | * [untag() (flask.json.tag.TaggedJSONSerializer method)](../api/#flask.json.tag.TaggedJSONSerializer.untag)

* [update() (flask.sessions.NullSession method)](../api/#flask.sessions.NullSession.update)

* [update\_template\_context() (flask.Flask method)](../api/#flask.Flask.update_template_context)

* [url (flask.Request property)](../api/#flask.Request.url)

* [url\_build\_error\_handlers (flask.Flask attribute)](../api/#flask.Flask.url_build_error_handlers)

* [url\_default\_functions (flask.Blueprint attribute)](../api/#flask.Blueprint.url_default_functions)
* [(flask.Flask attribute)](../api/#flask.Flask.url_default_functions)

* [url\_defaults (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.url_defaults)

* [url\_defaults() (flask.Blueprint method)](../api/#flask.Blueprint.url_defaults)
* [(flask.Flask method)](../api/#flask.Flask.url_defaults)

* [url\_for() (flask.Flask method)](../api/#flask.Flask.url_for)
* [(in module flask)](../api/#flask.url_for) | * [url\_map (flask.Flask attribute)](../api/#flask.Flask.url_map)

* [url\_map\_class (flask.Flask attribute)](../api/#flask.Flask.url_map_class)

* [url\_prefix (flask.blueprints.BlueprintSetupState attribute)](../api/#flask.blueprints.BlueprintSetupState.url_prefix)

* [url\_root (flask.Request property)](../api/#flask.Request.url_root)

* [url\_rule (flask.Request attribute)](../api/#flask.Request.url_rule)

* [url\_rule\_class (flask.Flask attribute)](../api/#flask.Flask.url_rule_class)

* [url\_value\_preprocessor() (flask.Blueprint method)](../api/#flask.Blueprint.url_value_preprocessor)
* [(flask.Flask method)](../api/#flask.Flask.url_value_preprocessor)

* [url\_value\_preprocessors (flask.Blueprint attribute)](../api/#flask.Blueprint.url_value_preprocessors)
* [(flask.Flask attribute)](../api/#flask.Flask.url_value_preprocessors)

* [USE\_X\_SENDFILE (built-in variable)](../config/#USE_X_SENDFILE)

* [user\_agent (flask.Request property)](../api/#flask.Request.user_agent)

* [user\_agent\_class (flask.Request attribute)](../api/#flask.Request.user_agent_class) | V - | | | | --- | --- | | * [values (flask.Request property)](../api/#flask.Request.values)

* [vary (flask.Response property)](../api/#flask.Response.vary)

* [View (class in flask.views)](../api/#flask.views.View) | * [view\_args (flask.Request attribute)](../api/#flask.Request.view_args)

* [view\_functions (flask.Blueprint attribute)](../api/#flask.Blueprint.view_functions)
* [(flask.Flask attribute)](../api/#flask.Flask.view_functions) | W - | | | | --- | --- | | * [want\_form\_data\_parsed (flask.Request property)](../api/#flask.Request.want_form_data_parsed)

* [with\_appcontext() (in module flask.cli)](../api/#flask.cli.with_appcontext) | * [wsgi\_app() (flask.Flask method)](../api/#flask.Flask.wsgi_app)

* [www\_authenticate (flask.Response property)](../api/#flask.Response.www_authenticate) | Y - * [YOURAPPLICATION\_SETTINGS](../config/#index-1) [![Logo of Flask](../_static/flask-vertical.png)](../) ### Navigation * [Overview](../) ### Quick search --- # Installation — Flask Documentation (3.1.x) ### Navigation * [index](../genindex/ "General Index") * [modules](../py-modindex/ "Python Module Index") | * [next](../quickstart/ "Quickstart") | * [previous](../ "Welcome to Flask") | * [Flask Documentation (3.1.x)](../) » * Installation Installation[¶](#installation "Link to this heading") ====================================================== Python Version[¶](#python-version "Link to this heading") ---------------------------------------------------------- We recommend using the latest version of Python. Flask supports Python 3.9 and newer. Dependencies[¶](#dependencies "Link to this heading") ------------------------------------------------------ These distributions will be installed automatically when installing Flask. * [Werkzeug](https://palletsprojects.com/p/werkzeug/) implements WSGI, the standard Python interface between applications and servers. * [Jinja](https://palletsprojects.com/p/jinja/) is a template language that renders the pages your application serves. * [MarkupSafe](https://palletsprojects.com/p/markupsafe/) comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks. * [ItsDangerous](https://palletsprojects.com/p/itsdangerous/) securely signs data to ensure its integrity. This is used to protect Flask’s session cookie. * [Click](https://palletsprojects.com/p/click/) is a framework for writing command line applications. It provides the `flask` command and allows adding custom management commands. * [Blinker](https://blinker.readthedocs.io/) provides support for [Signals](../signals/) . ### Optional dependencies[¶](#optional-dependencies "Link to this heading") These distributions will not be installed automatically. Flask will detect and use them if you install them. * [python-dotenv](https://github.com/theskumar/python-dotenv#readme) enables support for [Environment Variables From dotenv](../cli/#dotenv) when running `flask` commands. * [Watchdog](https://pythonhosted.org/watchdog/) provides a faster, more efficient reloader for the development server. ### greenlet[¶](#greenlet "Link to this heading") You may choose to use gevent or eventlet with your application. In this case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is required. These are not minimum supported versions, they only indicate the first versions that added necessary features. You should use the latest versions of each. Virtual environments[¶](#virtual-environments "Link to this heading") ---------------------------------------------------------------------- Use a virtual environment to manage the dependencies for your project, both in development and in production. What problem does a virtual environment solve? The more Python projects you have, the more likely it is that you need to work with different versions of Python libraries, or even Python itself. Newer versions of libraries for one project can break compatibility in another project. Virtual environments are independent groups of Python libraries, one for each project. Packages installed for one project will not affect other projects or the operating system’s packages. Python comes bundled with the [`venv`](https://docs.python.org/3/library/venv.html#module-venv "(in Python v3.13)") module to create virtual environments. ### Create an environment[¶](#create-an-environment "Link to this heading") Create a project folder and a `.venv` folder within: macOS/LinuxWindows $ mkdir myproject $ cd myproject $ python3 -m venv .venv \> mkdir myproject > cd myproject > py -3 -m venv .venv ### Activate the environment[¶](#activate-the-environment "Link to this heading") Before you work on your project, activate the corresponding environment: macOS/LinuxWindows $ . .venv/bin/activate \> .venv\\Scripts\\activate Your shell prompt will change to show the name of the activated environment. Install Flask[¶](#install-flask "Link to this heading") -------------------------------------------------------- Within the activated environment, use the following command to install Flask: $ pip install Flask Flask is now installed. Check out the [Quickstart](../quickstart/) or go to the [Documentation Overview](../) . [![Logo of Flask](../_static/flask-vertical.png)](../) ### Contents * [Installation](#) * [Python Version](#python-version) * [Dependencies](#dependencies) * [Optional dependencies](#optional-dependencies) * [greenlet](#greenlet) * [Virtual environments](#virtual-environments) * [Create an environment](#create-an-environment) * [Activate the environment](#activate-the-environment) * [Install Flask](#install-flask) ### Navigation * [Overview](../) * Previous: [Welcome to Flask](../ "previous chapter") * Next: [Quickstart](../quickstart/ "next chapter") ### Quick search --- # Quickstart — Flask Documentation (3.1.x) ### Navigation * [index](../genindex/ "General Index") * [modules](../py-modindex/ "Python Module Index") | * [next](../tutorial/ "Tutorial") | * [previous](../installation/ "Installation") | * [Flask Documentation (3.1.x)](../) » * Quickstart Quickstart[¶](#quickstart "Link to this heading") ================================================== Eager to get started? This page gives a good introduction to Flask. Follow [Installation](../installation/) to set up a project and install Flask first. A Minimal Application[¶](#a-minimal-application "Link to this heading") ------------------------------------------------------------------------ A minimal Flask application looks something like this: from flask import Flask app \= Flask(\_\_name\_\_) @app.route("/") def hello\_world(): return "

Hello, World!

" So what did that code do? 1. First we imported the [`Flask`](../api/#flask.Flask "flask.Flask") class. An instance of this class will be our WSGI application. 2. Next we create an instance of this class. The first argument is the name of the application’s module or package. `__name__` is a convenient shortcut for this that is appropriate for most cases. This is needed so that Flask knows where to look for resources such as templates and static files. 3. We then use the [`route()`](../api/#flask.Flask.route "flask.Flask.route") decorator to tell Flask what URL should trigger our function. 4. The function returns the message we want to display in the user’s browser. The default content type is HTML, so HTML in the string will be rendered by the browser. Save it as `hello.py` or something similar. Make sure to not call your application `flask.py` because this would conflict with Flask itself. To run the application, use the `flask` command or `python -m flask`. You need to tell the Flask where your application is with the `--app` option. $ flask --app hello run \* Serving Flask app 'hello' \* Running on http://127.0.0.1:5000 (Press CTRL+C to quit) Application Discovery Behavior As a shortcut, if the file is named `app.py` or `wsgi.py`, you don’t have to use `--app`. See [Command Line Interface](../cli/) for more details. This launches a very simple builtin server, which is good enough for testing but probably not what you want to use in production. For deployment options see [Deploying to Production](../deploying/) . Now head over to [http://127.0.0.1:5000/](http://127.0.0.1:5000/) , and you should see your hello world greeting. If another program is already using port 5000, you’ll see `OSError: [Errno 98]` or `OSError: [WinError 10013]` when the server tries to start. See [Address already in use](../server/#address-already-in-use) for how to handle that. Externally Visible Server If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer. If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding `--host=0.0.0.0` to the command line: $ flask run --host=0.0.0.0 This tells your operating system to listen on all public IPs. Debug Mode[¶](#debug-mode "Link to this heading") -------------------------------------------------- The `flask run` command can do more than just start the development server. By enabling debug mode, the server will automatically reload if code changes, and will show an interactive debugger in the browser if an error occurs during a request. ![The interactive debugger in action.](../_images/debugger.png) Warning The debugger allows executing arbitrary Python code from the browser. It is protected by a pin, but still represents a major security risk. Do not run the development server or debugger in a production environment. To enable debug mode, use the `--debug` option. $ flask --app hello run --debug \* Serving Flask app 'hello' \* Debug mode: on \* Running on http://127.0.0.1:5000 (Press CTRL+C to quit) \* Restarting with stat \* Debugger is active! \* Debugger PIN: nnn-nnn-nnn See also: * [Development Server](../server/) and [Command Line Interface](../cli/) for information about running in debug mode. * [Debugging Application Errors](../debugging/) for information about using the built-in debugger and other debuggers. * [Logging](../logging/) and [Handling Application Errors](../errorhandling/) to log errors and display nice error pages. HTML Escaping[¶](#html-escaping "Link to this heading") -------------------------------------------------------- When returning HTML (the default response type in Flask), any user-provided values rendered in the output must be escaped to protect from injection attacks. HTML templates rendered with Jinja, introduced later, will do this automatically. `escape()`, shown here, can be used manually. It is omitted in most examples for brevity, but you should always be aware of how you’re using untrusted data. from markupsafe import escape @app.route("/") def hello(name): return f"Hello, {escape(name)}!" If a user managed to submit the name ``, escaping causes it to be rendered as text, rather than running the script in the user’s browser. `` in the route captures a value from the URL and passes it to the view function. These variable rules are explained below. Routing[¶](#routing "Link to this heading") -------------------------------------------- Modern web applications use meaningful URLs to help users. Users are more likely to like a page and come back if the page uses a meaningful URL they can remember and use to directly visit a page. Use the [`route()`](../api/#flask.Flask.route "flask.Flask.route") decorator to bind a function to a URL. @app.route('/') def index(): return 'Index Page' @app.route('/hello') def hello(): return 'Hello, World' You can do more! You can make parts of the URL dynamic and attach multiple rules to a function. ### Variable Rules[¶](#variable-rules "Link to this heading") You can add variable sections to a URL by marking sections with ``. Your function then receives the `` as a keyword argument. Optionally, you can use a converter to specify the type of the argument like ``. from markupsafe import escape @app.route('/user/') def show\_user\_profile(username): \# show the user profile for that user return f'User {escape(username)}' @app.route('/post/') def show\_post(post\_id): \# show the post with the given id, the id is an integer return f'Post {post\_id}' @app.route('/path/') def show\_subpath(subpath): \# show the subpath after /path/ return f'Subpath {escape(subpath)}' Converter types: | | | | --- | --- | | `string` | (default) accepts any text without a slash | | `int` | accepts positive integers | | `float` | accepts positive floating point values | | `path` | like `string` but also accepts slashes | | `uuid` | accepts UUID strings | ### Unique URLs / Redirection Behavior[¶](#unique-urls-redirection-behavior "Link to this heading") The following two rules differ in their use of a trailing slash. @app.route('/projects/') def projects(): return 'The project page' @app.route('/about') def about(): return 'The about page' The canonical URL for the `projects` endpoint has a trailing slash. It’s similar to a folder in a file system. If you access the URL without a trailing slash (`/projects`), Flask redirects you to the canonical URL with the trailing slash (`/projects/`). The canonical URL for the `about` endpoint does not have a trailing slash. It’s similar to the pathname of a file. Accessing the URL with a trailing slash (`/about/`) produces a 404 “Not Found” error. This helps keep URLs unique for these resources, which helps search engines avoid indexing the same page twice. ### URL Building[¶](#url-building "Link to this heading") To build a URL to a specific function, use the [`url_for()`](../api/#flask.url_for "flask.url_for") function. It accepts the name of the function as its first argument and any number of keyword arguments, each corresponding to a variable part of the URL rule. Unknown variable parts are appended to the URL as query parameters. Why would you want to build URLs using the URL reversing function [`url_for()`](../api/#flask.url_for "flask.url_for") instead of hard-coding them into your templates? 1. Reversing is often more descriptive than hard-coding the URLs. 2. You can change your URLs in one go instead of needing to remember to manually change hard-coded URLs. 3. URL building handles escaping of special characters transparently. 4. The generated paths are always absolute, avoiding unexpected behavior of relative paths in browsers. 5. If your application is placed outside the URL root, for example, in `/myapplication` instead of `/`, [`url_for()`](../api/#flask.url_for "flask.url_for") properly handles that for you. For example, here we use the [`test_request_context()`](../api/#flask.Flask.test_request_context "flask.Flask.test_request_context") method to try out [`url_for()`](../api/#flask.url_for "flask.url_for") . [`test_request_context()`](../api/#flask.Flask.test_request_context "flask.Flask.test_request_context") tells Flask to behave as though it’s handling a request even while we use a Python shell. See [Context Locals](#context-locals) . from flask import url\_for @app.route('/') def index(): return 'index' @app.route('/login') def login(): return 'login' @app.route('/user/') def profile(username): return f'{username}\\'s profile' with app.test\_request\_context(): print(url\_for('index')) print(url\_for('login')) print(url\_for('login', next\='/')) print(url\_for('profile', username\='John Doe')) / /login /login?next=/ /user/John%20Doe ### HTTP Methods[¶](#http-methods "Link to this heading") Web applications use different HTTP methods when accessing URLs. You should familiarize yourself with the HTTP methods as you work with Flask. By default, a route only answers to `GET` requests. You can use the `methods` argument of the [`route()`](../api/#flask.Flask.route "flask.Flask.route") decorator to handle different HTTP methods. from flask import request @app.route('/login', methods\=\['GET', 'POST'\]) def login(): if request.method \== 'POST': return do\_the\_login() else: return show\_the\_login\_form() The example above keeps all methods for the route within one function, which can be useful if each part uses some common data. You can also separate views for different methods into different functions. Flask provides a shortcut for decorating such routes with [`get()`](../api/#flask.Flask.get "flask.Flask.get") , [`post()`](../api/#flask.Flask.post "flask.Flask.post") , etc. for each common HTTP method. @app.get('/login') def login\_get(): return show\_the\_login\_form() @app.post('/login') def login\_post(): return do\_the\_login() If `GET` is present, Flask automatically adds support for the `HEAD` method and handles `HEAD` requests according to the [HTTP RFC](https://www.ietf.org/rfc/rfc2068.txt) . Likewise, `OPTIONS` is automatically implemented for you. Static Files[¶](#static-files "Link to this heading") ------------------------------------------------------ Dynamic web applications also need static files. That’s usually where the CSS and JavaScript files are coming from. Ideally your web server is configured to serve them for you, but during development Flask can do that as well. Just create a folder called `static` in your package or next to your module and it will be available at `/static` on the application. To generate URLs for static files, use the special `'static'` endpoint name: url\_for('static', filename\='style.css') The file has to be stored on the filesystem as `static/style.css`. Rendering Templates[¶](#rendering-templates "Link to this heading") -------------------------------------------------------------------- Generating HTML from within Python is not fun, and actually pretty cumbersome because you have to do the HTML escaping on your own to keep the application secure. Because of that Flask configures the [Jinja2](https://palletsprojects.com/p/jinja/) template engine for you automatically. Templates can be used to generate any type of text file. For web applications, you’ll primarily be generating HTML pages, but you can also generate markdown, plain text for emails, and anything else. For a reference to HTML, CSS, and other web APIs, use the [MDN Web Docs](https://developer.mozilla.org/) . To render a template you can use the [`render_template()`](../api/#flask.render_template "flask.render_template") method. All you have to do is provide the name of the template and the variables you want to pass to the template engine as keyword arguments. Here’s a simple example of how to render a template: from flask import render\_template @app.route('/hello/') @app.route('/hello/') def hello(name\=None): return render\_template('hello.html', person\=name) Flask will look for templates in the `templates` folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package: **Case 1**: a module: /application.py /templates /hello.html **Case 2**: a package: /application /\_\_init\_\_.py /templates /hello.html For templates you can use the full power of Jinja2 templates. Head over to the official [Jinja2 Template Documentation](https://jinja.palletsprojects.com/templates/) for more information. Here is an example template: Hello from Flask {% if person %} Hello {{ person }}! {% else %} Hello, World! {% endif %} Inside templates you also have access to the [`config`](../api/#flask.Flask.config "flask.Flask.config") , [`request`](../api/#flask.request "flask.request") , [`session`](../api/#flask.session "flask.session") and [`g`](../api/#flask.g "flask.g") [\[1\]](#id3) objects as well as the [`url_for()`](../api/#flask.url_for "flask.url_for") and [`get_flashed_messages()`](../api/#flask.get_flashed_messages "flask.get_flashed_messages") functions. Templates are especially useful if inheritance is used. If you want to know how that works, see [Template Inheritance](../patterns/templateinheritance/) . Basically template inheritance makes it possible to keep certain elements on each page (like header, navigation and footer). Automatic escaping is enabled, so if `person` contains HTML it will be escaped automatically. If you can trust a variable and you know that it will be safe HTML (for example because it came from a module that converts wiki markup to HTML) you can mark it as safe by using the `Markup` class or by using the `|safe` filter in the template. Head over to the Jinja 2 documentation for more examples. Here is a basic introduction to how the `Markup` class works: \>>> from markupsafe import Markup \>>> Markup('Hello %s!') % 'hacker' Markup('Hello <blink>hacker</blink>!') \>>> Markup.escape('hacker') Markup('<blink>hacker</blink>') \>>> Markup('Marked up » HTML').striptags() 'Marked up » HTML' Changelog Changed in version 0.5: Autoescaping is no longer enabled for all templates. The following extensions for templates trigger autoescaping: `.html`, `.htm`, `.xml`, `.xhtml`. Templates loaded from a string will have autoescaping disabled. Accessing Request Data[¶](#accessing-request-data "Link to this heading") -------------------------------------------------------------------------- For web applications it’s crucial to react to the data a client sends to the server. In Flask this information is provided by the global [`request`](../api/#flask.request "flask.request") object. If you have some experience with Python you might be wondering how that object can be global and how Flask manages to still be threadsafe. The answer is context locals: ### Context Locals[¶](#context-locals "Link to this heading") Insider Information If you want to understand how that works and how you can implement tests with context locals, read this section, otherwise just skip it. Certain objects in Flask are global objects, but not of the usual kind. These objects are actually proxies to objects that are local to a specific context. What a mouthful. But that is actually quite easy to understand. Imagine the context being the handling thread. A request comes in and the web server decides to spawn a new thread (or something else, the underlying object is capable of dealing with concurrency systems other than threads). When Flask starts its internal request handling it figures out that the current thread is the active context and binds the current application and the WSGI environments to that context (thread). It does that in an intelligent way so that one application can invoke another application without breaking. So what does this mean to you? Basically you can completely ignore that this is the case unless you are doing something like unit testing. You will notice that code which depends on a request object will suddenly break because there is no request object. The solution is creating a request object yourself and binding it to the context. The easiest solution for unit testing is to use the [`test_request_context()`](../api/#flask.Flask.test_request_context "flask.Flask.test_request_context") context manager. In combination with the `with` statement it will bind a test request so that you can interact with it. Here is an example: from flask import request with app.test\_request\_context('/hello', method\='POST'): \# now you can do something with the request until the \# end of the with block, such as basic assertions: assert request.path \== '/hello' assert request.method \== 'POST' The other possibility is passing a whole WSGI environment to the [`request_context()`](../api/#flask.Flask.request_context "flask.Flask.request_context") method: with app.request\_context(environ): assert request.method \== 'POST' ### The Request Object[¶](#the-request-object "Link to this heading") The request object is documented in the API section and we will not cover it here in detail (see [`Request`](../api/#flask.Request "flask.Request") ). Here is a broad overview of some of the most common operations. First of all you have to import it from the `flask` module: from flask import request The current request method is available by using the [`method`](../api/#flask.Request.method "flask.Request.method") attribute. To access form data (data transmitted in a `POST` or `PUT` request) you can use the [`form`](../api/#flask.Request.form "flask.Request.form") attribute. Here is a full example of the two attributes mentioned above: @app.route('/login', methods\=\['POST', 'GET'\]) def login(): error \= None if request.method \== 'POST': if valid\_login(request.form\['username'\], request.form\['password'\]): return log\_the\_user\_in(request.form\['username'\]) else: error \= 'Invalid username/password' \# the code below is executed if the request method \# was GET or the credentials were invalid return render\_template('login.html', error\=error) What happens if the key does not exist in the `form` attribute? In that case a special [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.13)") is raised. You can catch it like a standard [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.13)") but if you don’t do that, a HTTP 400 Bad Request error page is shown instead. So for many situations you don’t have to deal with that problem. To access parameters submitted in the URL (`?key=value`) you can use the [`args`](../api/#flask.Request.args "flask.Request.args") attribute: searchword \= request.args.get('key', '') We recommend accessing URL parameters with `get` or by catching the [`KeyError`](https://docs.python.org/3/library/exceptions.html#KeyError "(in Python v3.13)") because users might change the URL and presenting them a 400 bad request page in that case is not user friendly. For a full list of methods and attributes of the request object, head over to the [`Request`](../api/#flask.Request "flask.Request") documentation. ### File Uploads[¶](#file-uploads "Link to this heading") You can handle uploaded files with Flask easily. Just make sure not to forget to set the `enctype="multipart/form-data"` attribute on your HTML form, otherwise the browser will not transmit your files at all. Uploaded files are stored in memory or at a temporary location on the filesystem. You can access those files by looking at the `files` attribute on the request object. Each uploaded file is stored in that dictionary. It behaves just like a standard Python `file` object, but it also has a [`save()`](https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage.save "(in Werkzeug v3.1.x)") method that allows you to store that file on the filesystem of the server. Here is a simple example showing how that works: from flask import request @app.route('/upload', methods\=\['GET', 'POST'\]) def upload\_file(): if request.method \== 'POST': f \= request.files\['the\_file'\] f.save('/var/www/uploads/uploaded\_file.txt') ... If you want to know how the file was named on the client before it was uploaded to your application, you can access the [`filename`](https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage.filename "(in Werkzeug v3.1.x)") attribute. However please keep in mind that this value can be forged so never ever trust that value. If you want to use the filename of the client to store the file on the server, pass it through the [`secure_filename()`](https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.utils.secure_filename "(in Werkzeug v3.1.x)") function that Werkzeug provides for you: from werkzeug.utils import secure\_filename @app.route('/upload', methods\=\['GET', 'POST'\]) def upload\_file(): if request.method \== 'POST': file \= request.files\['the\_file'\] file.save(f"/var/www/uploads/{secure\_filename(file.filename)}") ... For some better examples, see [Uploading Files](../patterns/fileuploads/) . ### Cookies[¶](#cookies "Link to this heading") To access cookies you can use the [`cookies`](../api/#flask.Request.cookies "flask.Request.cookies") attribute. To set cookies you can use the [`set_cookie`](../api/#flask.Response.set_cookie "flask.Response.set_cookie") method of response objects. The [`cookies`](../api/#flask.Request.cookies "flask.Request.cookies") attribute of request objects is a dictionary with all the cookies the client transmits. If you want to use sessions, do not use the cookies directly but instead use the [Sessions](#sessions) in Flask that add some security on top of cookies for you. Reading cookies: from flask import request @app.route('/') def index(): username \= request.cookies.get('username') \# use cookies.get(key) instead of cookies\[key\] to not get a \# KeyError if the cookie is missing. Storing cookies: from flask import make\_response @app.route('/') def index(): resp \= make\_response(render\_template(...)) resp.set\_cookie('username', 'the username') return resp Note that cookies are set on response objects. Since you normally just return strings from the view functions Flask will convert them into response objects for you. If you explicitly want to do that you can use the [`make_response()`](../api/#flask.make_response "flask.make_response") function and then modify it. Sometimes you might want to set a cookie at a point where the response object does not exist yet. This is possible by utilizing the [Deferred Request Callbacks](../patterns/deferredcallbacks/) pattern. For this also see [About Responses](#about-responses) . Redirects and Errors[¶](#redirects-and-errors "Link to this heading") ---------------------------------------------------------------------- To redirect a user to another endpoint, use the [`redirect()`](../api/#flask.redirect "flask.redirect") function; to abort a request early with an error code, use the [`abort()`](../api/#flask.abort "flask.abort") function: from flask import abort, redirect, url\_for @app.route('/') def index(): return redirect(url\_for('login')) @app.route('/login') def login(): abort(401) this\_is\_never\_executed() This is a rather pointless example because a user will be redirected from the index to a page they cannot access (401 means access denied) but it shows how that works. By default a black and white error page is shown for each error code. If you want to customize the error page, you can use the [`errorhandler()`](../api/#flask.Flask.errorhandler "flask.Flask.errorhandler") decorator: from flask import render\_template @app.errorhandler(404) def page\_not\_found(error): return render\_template('page\_not\_found.html'), 404 Note the `404` after the [`render_template()`](../api/#flask.render_template "flask.render_template") call. This tells Flask that the status code of that page should be 404 which means not found. By default 200 is assumed which translates to: all went well. See [Handling Application Errors](../errorhandling/) for more details. About Responses[¶](#about-responses "Link to this heading") ------------------------------------------------------------ The return value from a view function is automatically converted into a response object for you. If the return value is a string it’s converted into a response object with the string as response body, a `200 OK` status code and a _text/html_ mimetype. If the return value is a dict or list, `jsonify()` is called to produce a response. The logic that Flask applies to converting return values into response objects is as follows: 1. If a response object of the correct type is returned it’s directly returned from the view. 2. If it’s a string, a response object is created with that data and the default parameters. 3. If it’s an iterator or generator returning strings or bytes, it is treated as a streaming response. 4. If it’s a dict or list, a response object is created using [`jsonify()`](../api/#flask.json.jsonify "flask.json.jsonify") . 5. If a tuple is returned the items in the tuple can provide extra information. Such tuples have to be in the form `(response, status)`, `(response, headers)`, or `(response, status, headers)`. The `status` value will override the status code and `headers` can be a list or dictionary of additional header values. 6. If none of that works, Flask will assume the return value is a valid WSGI application and convert that into a response object. If you want to get hold of the resulting response object inside the view you can use the [`make_response()`](../api/#flask.make_response "flask.make_response") function. Imagine you have a view like this: from flask import render\_template @app.errorhandler(404) def not\_found(error): return render\_template('error.html'), 404 You just need to wrap the return expression with [`make_response()`](../api/#flask.make_response "flask.make_response") and get the response object to modify it, then return it: from flask import make\_response @app.errorhandler(404) def not\_found(error): resp \= make\_response(render\_template('error.html'), 404) resp.headers\['X-Something'\] \= 'A value' return resp ### APIs with JSON[¶](#apis-with-json "Link to this heading") A common response format when writing an API is JSON. It’s easy to get started writing such an API with Flask. If you return a `dict` or `list` from a view, it will be converted to a JSON response. @app.route("/me") def me\_api(): user \= get\_current\_user() return { "username": user.username, "theme": user.theme, "image": url\_for("user\_image", filename\=user.image), } @app.route("/users") def users\_api(): users \= get\_all\_users() return \[user.to\_json() for user in users\] This is a shortcut to passing the data to the [`jsonify()`](../api/#flask.json.jsonify "flask.json.jsonify") function, which will serialize any supported JSON data type. That means that all the data in the dict or list must be JSON serializable. For complex types such as database models, you’ll want to use a serialization library to convert the data to valid JSON types first. There are many serialization libraries and Flask API extensions maintained by the community that support more complex applications. Sessions[¶](#sessions "Link to this heading") ---------------------------------------------- In addition to the request object there is also a second object called [`session`](../api/#flask.session "flask.session") which allows you to store information specific to a user from one request to the next. This is implemented on top of cookies for you and signs the cookies cryptographically. What this means is that the user could look at the contents of your cookie but not modify it, unless they know the secret key used for signing. In order to use sessions you have to set a secret key. Here is how sessions work: from flask import session \# Set the secret key to some random bytes. Keep this really secret! app.secret\_key \= b'\_5#y2L"F4Q8z\\n\\xec\]/' @app.route('/') def index(): if 'username' in session: return f'Logged in as {session\["username"\]}' return 'You are not logged in' @app.route('/login', methods\=\['GET', 'POST'\]) def login(): if request.method \== 'POST': session\['username'\] \= request.form\['username'\] return redirect(url\_for('index')) return '''

''' @app.route('/logout') def logout(): \# remove the username from the session if it's there session.pop('username', None) return redirect(url\_for('index')) How to generate good secret keys A secret key should be as random as possible. Your operating system has ways to generate pretty random data based on a cryptographic random generator. Use the following command to quickly generate a value for `Flask.secret_key` (or [`SECRET_KEY`](../config/#SECRET_KEY "SECRET_KEY") ): $ python -c 'import secrets; print(secrets.token\_hex())' '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' A note on cookie-based sessions: Flask will take the values you put into the session object and serialize them into a cookie. If you are finding some values do not persist across requests, cookies are indeed enabled, and you are not getting a clear error message, check the size of the cookie in your page responses compared to the size supported by web browsers. Besides the default client-side based sessions, if you want to handle sessions on the server-side instead, there are several Flask extensions that support this. Message Flashing[¶](#message-flashing "Link to this heading") -------------------------------------------------------------- Good applications and user interfaces are all about feedback. If the user does not get enough feedback they will probably end up hating the application. Flask provides a really simple way to give feedback to a user with the flashing system. The flashing system basically makes it possible to record a message at the end of a request and access it on the next (and only the next) request. This is usually combined with a layout template to expose the message. To flash a message use the [`flash()`](../api/#flask.flash "flask.flash") method, to get hold of the messages you can use [`get_flashed_messages()`](../api/#flask.get_flashed_messages "flask.get_flashed_messages") which is also available in the templates. See [Message Flashing](../patterns/flashing/) for a full example. Logging[¶](#logging "Link to this heading") -------------------------------------------- Changelog Added in version 0.3. Sometimes you might be in a situation where you deal with data that should be correct, but actually is not. For example you may have some client-side code that sends an HTTP request to the server but it’s obviously malformed. This might be caused by a user tampering with the data, or the client code failing. Most of the time it’s okay to reply with `400 Bad Request` in that situation, but sometimes that won’t do and the code has to continue working. You may still want to log that something fishy happened. This is where loggers come in handy. As of Flask 0.3 a logger is preconfigured for you to use. Here are some example log calls: app.logger.debug('A value for debugging') app.logger.warning('A warning occurred (%d apples)', 42) app.logger.error('An error occurred') The attached [`logger`](../api/#flask.Flask.logger "flask.Flask.logger") is a standard logging [`Logger`](https://docs.python.org/3/library/logging.html#logging.Logger "(in Python v3.13)") , so head over to the official [`logging`](https://docs.python.org/3/library/logging.html#module-logging "(in Python v3.13)") docs for more information. See [Handling Application Errors](../errorhandling/) . Hooking in WSGI Middleware[¶](#hooking-in-wsgi-middleware "Link to this heading") ---------------------------------------------------------------------------------- To add WSGI middleware to your Flask application, wrap the application’s `wsgi_app` attribute. For example, to apply Werkzeug’s [`ProxyFix`](https://werkzeug.palletsprojects.com/en/stable/middleware/proxy_fix/#werkzeug.middleware.proxy_fix.ProxyFix "(in Werkzeug v3.1.x)") middleware for running behind Nginx: from werkzeug.middleware.proxy\_fix import ProxyFix app.wsgi\_app \= ProxyFix(app.wsgi\_app) Wrapping `app.wsgi_app` instead of `app` means that `app` still points at your Flask application, not at the middleware, so you can continue to use and configure `app` directly. Using Flask Extensions[¶](#using-flask-extensions "Link to this heading") -------------------------------------------------------------------------- Extensions are packages that help you accomplish common tasks. For example, Flask-SQLAlchemy provides SQLAlchemy support that makes it simple and easy to use with Flask. For more on Flask extensions, see [Extensions](../extensions/) . Deploying to a Web Server[¶](#deploying-to-a-web-server "Link to this heading") -------------------------------------------------------------------------------- Ready to deploy your new Flask app? See [Deploying to Production](../deploying/) . [![Logo of Flask](../_static/flask-vertical.png)](../) ### Contents * [Quickstart](#) * [A Minimal Application](#a-minimal-application) * [Debug Mode](#debug-mode) * [HTML Escaping](#html-escaping) * [Routing](#routing) * [Variable Rules](#variable-rules) * [Unique URLs / Redirection Behavior](#unique-urls-redirection-behavior) * [URL Building](#url-building) * [HTTP Methods](#http-methods) * [Static Files](#static-files) * [Rendering Templates](#rendering-templates) * [Accessing Request Data](#accessing-request-data) * [Context Locals](#context-locals) * [The Request Object](#the-request-object) * [File Uploads](#file-uploads) * [Cookies](#cookies) * [Redirects and Errors](#redirects-and-errors) * [About Responses](#about-responses) * [APIs with JSON](#apis-with-json) * [Sessions](#sessions) * [Message Flashing](#message-flashing) * [Logging](#logging) * [Hooking in WSGI Middleware](#hooking-in-wsgi-middleware) * [Using Flask Extensions](#using-flask-extensions) * [Deploying to a Web Server](#deploying-to-a-web-server) ### Navigation * [Overview](../) * Previous: [Installation](../installation/ "previous chapter") * Next: [Tutorial](../tutorial/ "next chapter") ### Quick search --- # Tutorial — Flask Documentation (3.1.x) ### Navigation * [index](../genindex/ "General Index") * [modules](../py-modindex/ "Python Module Index") | * [next](layout/ "Project Layout") | * [previous](../quickstart/ "Quickstart") | * [Flask Documentation (3.1.x)](../) » * Tutorial Tutorial[¶](#tutorial "Link to this heading") ============================================== Contents: * [Project Layout](layout/) * [Application Setup](factory/) * [Define and Access the Database](database/) * [Blueprints and Views](views/) * [Templates](templates/) * [Static Files](static/) * [Blog Blueprint](blog/) * [Make the Project Installable](install/) * [Test Coverage](tests/) * [Deploy to Production](deploy/) * [Keep Developing!](next/) This tutorial will walk you through creating a basic blog application called Flaskr. Users will be able to register, log in, create posts, and edit or delete their own posts. You will be able to package and install the application on other computers. ![screenshot of index page](../_images/flaskr_index.png) It’s assumed that you’re already familiar with Python. The [official tutorial](https://docs.python.org/3/tutorial/) in the Python docs is a great way to learn or review first. While it’s designed to give a good starting point, the tutorial doesn’t cover all of Flask’s features. Check out the [Quickstart](../quickstart/) for an overview of what Flask can do, then dive into the docs to find out more. The tutorial only uses what’s provided by Flask and Python. In another project, you might decide to use [Extensions](../extensions/) or other libraries to make some tasks simpler. ![screenshot of login page](../_images/flaskr_login.png) Flask is flexible. It doesn’t require you to use any particular project or code layout. However, when first starting, it’s helpful to use a more structured approach. This means that the tutorial will require a bit of boilerplate up front, but it’s done to avoid many common pitfalls that new developers encounter, and it creates a project that’s easy to expand on. Once you become more comfortable with Flask, you can step out of this structure and take full advantage of Flask’s flexibility. ![screenshot of edit page](../_images/flaskr_edit.png) [The tutorial project is available as an example in the Flask repository](https://github.com/pallets/flask/tree/main/examples/tutorial) , if you want to compare your project with the final product as you follow the tutorial. Continue to [Project Layout](layout/) . [![Logo of Flask](../_static/flask-vertical.png)](../) ### Navigation * [Overview](../) * Previous: [Quickstart](../quickstart/ "previous chapter") * Next: [Project Layout](layout/ "next chapter") ### Quick search --- # Python Module Index — Flask Documentation (3.1.x) ### Navigation * [index](../genindex/ "General Index") * [modules](# "Python Module Index") | * [Flask Documentation (3.1.x)](../) » * Python Module Index Python Module Index =================== [**f**](#cap-f) | | | | | --- | --- | --- | | | | | | | **f** | | | ![-](../_static/minus.png) | [`flask`](../api/#module-flask) | | | | [`flask.json`](../api/#module-flask.json) | | | | [`flask.json.tag`](../api/#module-flask.json.tag) | | [![Logo of Flask](../_static/flask-vertical.png)](../) ### Navigation * [Overview](../) ### Quick search --- # Patterns for Flask — Flask Documentation (3.1.x) ### Navigation * [index](../genindex/ "General Index") * [modules](../py-modindex/ "Python Module Index") | * [next](packages/ "Large Applications as Packages") | * [previous](../shell/ "Working with the Shell") | * [Flask Documentation (3.1.x)](../) » * Patterns for Flask Patterns for Flask[¶](#patterns-for-flask "Link to this heading") ================================================================== Certain features and interactions are common enough that you will find them in most web applications. For example, many applications use a relational database and user authentication. They will open a database connection at the beginning of the request and get the information for the logged in user. At the end of the request, the database connection is closed. These types of patterns may be a bit outside the scope of Flask itself, but Flask makes it easy to implement them. Some common patterns are collected in the following pages. * [Large Applications as Packages](packages/) * [Simple Packages](packages/#simple-packages) * [Working with Blueprints](packages/#working-with-blueprints) * [Application Factories](appfactories/) * [Basic Factories](appfactories/#basic-factories) * [Factories & Extensions](appfactories/#factories-extensions) * [Using Applications](appfactories/#using-applications) * [Factory Improvements](appfactories/#factory-improvements) * [Application Dispatching](appdispatch/) * [Working with this Document](appdispatch/#working-with-this-document) * [Combining Applications](appdispatch/#combining-applications) * [Dispatch by Subdomain](appdispatch/#dispatch-by-subdomain) * [Dispatch by Path](appdispatch/#dispatch-by-path) * [Using URL Processors](urlprocessors/) * [Internationalized Application URLs](urlprocessors/#internationalized-application-urls) * [Internationalized Blueprint URLs](urlprocessors/#internationalized-blueprint-urls) * [Using SQLite 3 with Flask](sqlite3/) * [Connect on Demand](sqlite3/#connect-on-demand) * [Easy Querying](sqlite3/#easy-querying) * [Initial Schemas](sqlite3/#initial-schemas) * [SQLAlchemy in Flask](sqlalchemy/) * [Flask-SQLAlchemy Extension](sqlalchemy/#flask-sqlalchemy-extension) * [Declarative](sqlalchemy/#declarative) * [Manual Object Relational Mapping](sqlalchemy/#manual-object-relational-mapping) * [SQL Abstraction Layer](sqlalchemy/#sql-abstraction-layer) * [Uploading Files](fileuploads/) * [A Gentle Introduction](fileuploads/#a-gentle-introduction) * [Improving Uploads](fileuploads/#improving-uploads) * [Upload Progress Bars](fileuploads/#upload-progress-bars) * [An Easier Solution](fileuploads/#an-easier-solution) * [Caching](caching/) * [View Decorators](viewdecorators/) * [Login Required Decorator](viewdecorators/#login-required-decorator) * [Caching Decorator](viewdecorators/#caching-decorator) * [Templating Decorator](viewdecorators/#templating-decorator) * [Endpoint Decorator](viewdecorators/#endpoint-decorator) * [Form Validation with WTForms](wtforms/) * [The Forms](wtforms/#the-forms) * [In the View](wtforms/#in-the-view) * [Forms in Templates](wtforms/#forms-in-templates) * [Template Inheritance](templateinheritance/) * [Base Template](templateinheritance/#base-template) * [Child Template](templateinheritance/#child-template) * [Message Flashing](flashing/) * [Simple Flashing](flashing/#simple-flashing) * [Flashing With Categories](flashing/#flashing-with-categories) * [Filtering Flash Messages](flashing/#filtering-flash-messages) * [JavaScript, `fetch`, and JSON](javascript/) * [Rendering Templates](javascript/#rendering-templates) * [Generating URLs](javascript/#generating-urls) * [Making a Request with `fetch`](javascript/#making-a-request-with-fetch) * [Following Redirects](javascript/#following-redirects) * [Replacing Content](javascript/#replacing-content) * [Return JSON from Views](javascript/#return-json-from-views) * [Receiving JSON in Views](javascript/#receiving-json-in-views) * [Lazily Loading Views](lazyloading/) * [Converting to Centralized URL Map](lazyloading/#converting-to-centralized-url-map) * [Loading Late](lazyloading/#loading-late) * [MongoDB with MongoEngine](mongoengine/) * [Configuration](mongoengine/#configuration) * [Mapping Documents](mongoengine/#mapping-documents) * [Creating Data](mongoengine/#creating-data) * [Queries](mongoengine/#queries) * [Documentation](mongoengine/#documentation) * [Adding a favicon](favicon/) * [See also](favicon/#see-also) * [Streaming Contents](streaming/) * [Basic Usage](streaming/#basic-usage) * [Streaming from Templates](streaming/#streaming-from-templates) * [Streaming with Context](streaming/#streaming-with-context) * [Deferred Request Callbacks](deferredcallbacks/) * [Adding HTTP Method Overrides](methodoverrides/) * [Request Content Checksums](requestchecksum/) * [Background Tasks with Celery](celery/) * [Install](celery/#install) * [Integrate Celery with Flask](celery/#integrate-celery-with-flask) * [Application Factory](celery/#application-factory) * [Defining Tasks](celery/#defining-tasks) * [Calling Tasks](celery/#calling-tasks) * [Getting Results](celery/#getting-results) * [Passing Data to Tasks](celery/#passing-data-to-tasks) * [Subclassing Flask](subclassing/) * [Single-Page Applications](singlepageapplications/) [![Logo of Flask](../_static/flask-vertical.png)](../) ### Navigation * [Overview](../) * Previous: [Working with the Shell](../shell/ "previous chapter") * Next: [Large Applications as Packages](packages/ "next chapter") ### Quick search --- # Project Layout — Flask Documentation (3.1.x) ### Navigation * [index](../../genindex/ "General Index") * [modules](../../py-modindex/ "Python Module Index") | * [next](../factory/ "Application Setup") | * [previous](../ "Tutorial") | * [Flask Documentation (3.1.x)](../../) » * [Tutorial](../) » * Project Layout Project Layout[¶](#project-layout "Link to this heading") ========================================================== Create a project directory and enter it: $ mkdir flask-tutorial $ cd flask-tutorial Then follow the [installation instructions](../../installation/) to set up a Python virtual environment and install Flask for your project. The tutorial will assume you’re working from the `flask-tutorial` directory from now on. The file names at the top of each code block are relative to this directory. * * * A Flask application can be as simple as a single file. `hello.py`[¶](#id1 "Link to this code") from flask import Flask app \= Flask(\_\_name\_\_) @app.route('/') def hello(): return 'Hello, World!' However, as a project gets bigger, it becomes overwhelming to keep all the code in one file. Python projects use _packages_ to organize code into multiple modules that can be imported where needed, and the tutorial will do this as well. The project directory will contain: * `flaskr/`, a Python package containing your application code and files. * `tests/`, a directory containing test modules. * `.venv/`, a Python virtual environment where Flask and other dependencies are installed. * Installation files telling Python how to install your project. * Version control config, such as [git](https://git-scm.com/) . You should make a habit of using some type of version control for all your projects, no matter the size. * Any other project files you might add in the future. By the end, your project layout will look like this: /home/user/Projects/flask-tutorial ├── flaskr/ │ ├── \_\_init\_\_.py │ ├── db.py │ ├── schema.sql │ ├── auth.py │ ├── blog.py │ ├── templates/ │ │ ├── base.html │ │ ├── auth/ │ │ │ ├── login.html │ │ │ └── register.html │ │ └── blog/ │ │ ├── create.html │ │ ├── index.html │ │ └── update.html │ └── static/ │ └── style.css ├── tests/ │ ├── conftest.py │ ├── data.sql │ ├── test\_factory.py │ ├── test\_db.py │ ├── test\_auth.py │ └── test\_blog.py ├── .venv/ ├── pyproject.toml └── MANIFEST.in If you’re using version control, the following files that are generated while running your project should be ignored. There may be other files based on the editor you use. In general, ignore files that you didn’t write. For example, with git: `.gitignore`[¶](#id2 "Link to this code") .venv/ \*.pyc \_\_pycache\_\_/ instance/ .pytest\_cache/ .coverage htmlcov/ dist/ build/ \*.egg-info/ Continue to [Application Setup](../factory/) . [![Logo of Flask](../../_static/flask-vertical.png)](../../) ### Navigation * [Overview](../../) * [Tutorial](../) * Previous: [Tutorial](../ "previous chapter") * Next: [Application Setup](../factory/ "next chapter") ### Quick search --- # Templates — Flask Documentation (3.1.x) ### Navigation * [index](../../genindex/ "General Index") * [modules](../../py-modindex/ "Python Module Index") | * [next](../static/ "Static Files") | * [previous](../views/ "Blueprints and Views") | * [Flask Documentation (3.1.x)](../../) » * [Tutorial](../) » * Templates Templates[¶](#templates "Link to this heading") ================================================ You’ve written the authentication views for your application, but if you’re running the server and try to go to any of the URLs, you’ll see a `TemplateNotFound` error. That’s because the views are calling [`render_template()`](../../api/#flask.render_template "flask.render_template") , but you haven’t written the templates yet. The template files will be stored in the `templates` directory inside the `flaskr` package. Templates are files that contain static data as well as placeholders for dynamic data. A template is rendered with specific data to produce a final document. Flask uses the [Jinja](https://jinja.palletsprojects.com/templates/) template library to render templates. In your application, you will use templates to render [HTML](https://developer.mozilla.org/docs/Web/HTML) which will display in the user’s browser. In Flask, Jinja is configured to _autoescape_ any data that is rendered in HTML templates. This means that it’s safe to render user input; any characters they’ve entered that could mess with the HTML, such as `<` and `>` will be _escaped_ with _safe_ values that look the same in the browser but don’t cause unwanted effects. Jinja looks and behaves mostly like Python. Special delimiters are used to distinguish Jinja syntax from the static data in the template. Anything between `{{` and `}}` is an expression that will be output to the final document. `{%` and `%}` denotes a control flow statement like `if` and `for`. Unlike Python, blocks are denoted by start and end tags rather than indentation since static text within a block could change indentation. The Base Layout[¶](#the-base-layout "Link to this heading") ------------------------------------------------------------ Each page in the application will have the same basic layout around a different body. Instead of writing the entire HTML structure in each template, each template will _extend_ a base template and override specific sections. `flaskr/templates/base.html`[¶](#id1 "Link to this code") {% block title %}{% endblock %} - Flaskr Flaskr {% if g.user %} {{ g.user\['username'\] }} Log Out {% else %} Register Log In {% endif %}
{% block header %}{% endblock %} {% for message in get\_flashed\_messages() %}
{{ message }} {% endfor %} {% block content %}{% endblock %} [`g`](../../api/#flask.g "flask.g") is automatically available in templates. Based on if `g.user` is set (from `load_logged_in_user`), either the username and a log out link are displayed, or links to register and log in are displayed. [`url_for()`](../../api/#flask.url_for "flask.url_for") is also automatically available, and is used to generate URLs to views instead of writing them out manually. After the page title, and before the content, the template loops over each message returned by [`get_flashed_messages()`](../../api/#flask.get_flashed_messages "flask.get_flashed_messages") . You used [`flash()`](../../api/#flask.flash "flask.flash") in the views to show error messages, and this is the code that will display them. There are three blocks defined here that will be overridden in the other templates: 1. `{% block title %}` will change the title displayed in the browser’s tab and window title. 2. `{% block header %}` is similar to `title` but will change the title displayed on the page. 3. `{% block content %}` is where the content of each page goes, such as the login form or a blog post. The base template is directly in the `templates` directory. To keep the others organized, the templates for a blueprint will be placed in a directory with the same name as the blueprint. Register[¶](#register "Link to this heading") ---------------------------------------------- `flaskr/templates/auth/register.html`[¶](#id2 "Link to this code") {% extends 'base.html' %} {% block header %} {% block title %}Register{% endblock %} {% endblock %} {% block content %}
New {% endif %} {% endblock %} {% block content %} {% for post in posts %}
{{ post\['title'\] }}
by {{ post\['username'\] }} on {{ post\['created'\].strftime('%Y-%m-%d') }} {% if g.user\['id'\] \== post\['author\_id'\] %} Edit {% endif %}

{{ post\['body'\] }} {% if not loop.last %} {% endif %} {% endfor %} {% endblock %} When a user is logged in, the `header` block adds a link to the `create` view. When the user is the author of a post, they’ll see an “Edit” link to the `update` view for that post. `loop.last` is a special variable available inside [Jinja for loops](https://jinja.palletsprojects.com/templates/#for) . It’s used to display a line after each post except the last one, to visually separate them. Create[¶](#create "Link to this heading") ------------------------------------------ The `create` view works the same as the auth `register` view. Either the form is displayed, or the posted data is validated and the post is added to the database or an error is shown. The `login_required` decorator you wrote earlier is used on the blog views. A user must be logged in to visit these views, otherwise they will be redirected to the login page. `flaskr/blog.py`[¶](#id5 "Link to this code") @bp.route('/create', methods\=('GET', 'POST')) @login\_required def create(): if request.method \== 'POST': title \= request.form\['title'\] body \= request.form\['body'\] error \= None if not title: error \= 'Title is required.' if error is not None: flash(error) else: db \= get\_db() db.execute( 'INSERT INTO post (title, body, author\_id)' ' VALUES (?, ?, ?)', (title, body, g.user\['id'\]) ) db.commit() return redirect(url\_for('blog.index')) return render\_template('blog/create.html') `flaskr/templates/blog/create.html`[¶](#id6 "Link to this code") {% extends 'base.html' %} {% block header %} {% block title %}New Post{% endblock %} {% endblock %} {% block content %}