CINXE.COM

API — Flask Documentation (3.1.x)

<!DOCTYPE html> <html lang="en" data-content_root="../"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>API &#8212; Flask Documentation (3.1.x)</title> <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" /> <link rel="stylesheet" type="text/css" href="../_static/flask.css?v=b87c8d14" /> <script src="../_static/documentation_options.js?v=d71c4578"></script> <script src="../_static/doctools.js?v=9bcbadda"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <link rel="canonical" href="https://flask.palletsprojects.com/en/stable/api/" /> <link rel="icon" href="../_static/shortcut-icon.png"/> <link rel="index" title="Index" href="../genindex/" /> <link rel="search" title="Search" href="../search/" /> <link rel="next" title="Design Decisions in Flask" href="../design/" /> <link rel="prev" title="Using async and await" href="../async-await/" /> <script async type="text/javascript" src="/_/static/javascript/readthedocs-addons.js"></script><meta name="readthedocs-project-slug" content="flask" /><meta name="readthedocs-version-slug" content="stable" /><meta name="readthedocs-resolver-filename" content="/api/" /><meta name="readthedocs-http-status" content="200" /></head><body> <div class="related" role="navigation" aria-label="Related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex/" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex/" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="../design/" title="Design Decisions in Flask" accesskey="N">next</a> |</li> <li class="right" > <a href="../async-await/" title="Using async and await" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../">Flask Documentation (3.1.x)</a> &#187;</li> <li class="nav-item nav-item-this"><a href="">API</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="module-flask"> <span id="api"></span><h1>API<a class="headerlink" href="#module-flask" title="Link to this heading">¶</a></h1> <p>This part of the documentation covers all the interfaces of Flask. For parts where Flask depends on external libraries, we document the most important right here and provide links to the canonical documentation.</p> <section id="application-object"> <h2>Application Object<a class="headerlink" href="#application-object" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.Flask"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">Flask</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">import_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">static_url_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">static_folder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'static'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">static_host</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">host_matching</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subdomain_matching</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">template_folder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'templates'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">instance_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">instance_relative_config</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">root_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask" title="Link to this definition">¶</a></dt> <dd><p>The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package of the application. Once it is created it will act as a central registry for the view functions, the URL rules, template configuration and much more.</p> <p>The name of the package is used to resolve resources from inside the package or the folder the module is contained in depending on if the package parameter resolves to an actual python package (a folder with an <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> file inside) or a standard module (just a <code class="docutils literal notranslate"><span class="pre">.py</span></code> file).</p> <p>For more information about resource loading, see <a class="reference internal" href="#flask.Flask.open_resource" title="flask.Flask.open_resource"><code class="xref py py-func docutils literal notranslate"><span class="pre">open_resource()</span></code></a>.</p> <p>Usually you create a <a class="reference internal" href="#flask.Flask" title="flask.Flask"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flask</span></code></a> instance in your main module or in the <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> file of your package like this:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> </pre></div> </div> <div class="admonition-about-the-first-parameter admonition"> <p class="admonition-title">About the First Parameter</p> <p>The idea of the first parameter is to give Flask an idea of what belongs to your application. This name is used to find resources on the filesystem, can be used by extensions to improve debugging information and a lot more.</p> <p>So it’s important what you provide there. If you are using a single module, <code class="code docutils literal notranslate"><span class="pre">__name__</span></code> is always the correct value. If you however are using a package, it’s usually recommended to hardcode the name of your package there.</p> <p>For example if your application is defined in <code class="file docutils literal notranslate"><span class="pre">yourapplication/app.py</span></code> you should create it with one of the two versions below:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="s1">&#39;yourapplication&#39;</span><span class="p">)</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="vm">__name__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> </pre></div> </div> <p>Why is that? The application will work even with <code class="code docutils literal notranslate"><span class="pre">__name__</span></code>, thanks to how resources are looked up. However it will make debugging more painful. Certain extensions can make assumptions based on the import name of your application. For example the Flask-SQLAlchemy extension will look for the code in your application that triggered an SQL query in debug mode. If the import name is not properly set up, that debugging information is lost. (For example it would only pick up SQL queries in <code class="code docutils literal notranslate"><span class="pre">yourapplication.app</span></code> and not <code class="code docutils literal notranslate"><span class="pre">yourapplication.views.frontend</span></code>)</p> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 1.0: </span>The <code class="docutils literal notranslate"><span class="pre">host_matching</span></code> and <code class="docutils literal notranslate"><span class="pre">static_host</span></code> parameters were added.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 1.0: </span>The <code class="docutils literal notranslate"><span class="pre">subdomain_matching</span></code> parameter was added. Subdomain matching needs to be enabled manually now. Setting <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a> does not implicitly enable it.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11: </span>The <code class="code docutils literal notranslate"><span class="pre">root_path</span></code> parameter was added.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8: </span>The <code class="code docutils literal notranslate"><span class="pre">instance_path</span></code> and <code class="code docutils literal notranslate"><span class="pre">instance_relative_config</span></code> parameters were added.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>The <code class="code docutils literal notranslate"><span class="pre">static_url_path</span></code>, <code class="code docutils literal notranslate"><span class="pre">static_folder</span></code>, and <code class="code docutils literal notranslate"><span class="pre">template_folder</span></code> parameters were added.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>import_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the name of the application package</p></li> <li><p><strong>static_url_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – can be used to specify a different path for the static files on the web. Defaults to the name of the <code class="code docutils literal notranslate"><span class="pre">static_folder</span></code> folder.</p></li> <li><p><strong>static_folder</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><em>None</em>) – The folder with static files that is served at <code class="docutils literal notranslate"><span class="pre">static_url_path</span></code>. Relative to the application <code class="docutils literal notranslate"><span class="pre">root_path</span></code> or an absolute path. Defaults to <code class="docutils literal notranslate"><span class="pre">'static'</span></code>.</p></li> <li><p><strong>static_host</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the host to use when adding the static route. Defaults to None. Required when using <code class="docutils literal notranslate"><span class="pre">host_matching=True</span></code> with a <code class="docutils literal notranslate"><span class="pre">static_folder</span></code> configured.</p></li> <li><p><strong>host_matching</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – set <code class="docutils literal notranslate"><span class="pre">url_map.host_matching</span></code> attribute. Defaults to False.</p></li> <li><p><strong>subdomain_matching</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – consider the subdomain relative to <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a> when matching routes. Defaults to False.</p></li> <li><p><strong>template_folder</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><em>None</em>) – the folder that contains the templates that should be used by the application. Defaults to <code class="docutils literal notranslate"><span class="pre">'templates'</span></code> folder in the root path of the application.</p></li> <li><p><strong>instance_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – An alternative instance path for the application. By default the folder <code class="docutils literal notranslate"><span class="pre">'instance'</span></code> next to the package or module is assumed to be the instance path.</p></li> <li><p><strong>instance_relative_config</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – if set to <code class="docutils literal notranslate"><span class="pre">True</span></code> relative filenames for loading the config are assumed to be relative to the instance path instead of the application root.</p></li> <li><p><strong>root_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – The path to the root of the application files. This should only be set manually when it can’t be detected automatically, such as for namespace packages.</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.request_class"> <span class="sig-name descname"><span class="pre">request_class</span></span><a class="headerlink" href="#flask.Flask.request_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.Request" title="flask.wrappers.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a></p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.response_class"> <span class="sig-name descname"><span class="pre">response_class</span></span><a class="headerlink" href="#flask.Flask.response_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a></p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.session_interface"> <span class="sig-name descname"><span class="pre">session_interface</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference internal" href="#flask.sessions.SessionInterface" title="flask.sessions.SessionInterface"><span class="pre">SessionInterface</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">&lt;flask.sessions.SecureCookieSessionInterface</span> <span class="pre">object&gt;</span></em><a class="headerlink" href="#flask.Flask.session_interface" title="Link to this definition">¶</a></dt> <dd><p>the session interface to use. By default an instance of <a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface" title="flask.sessions.SecureCookieSessionInterface"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecureCookieSessionInterface</span></code></a> is used here.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.cli"> <span class="sig-name descname"><span class="pre">cli</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Group</span></em><a class="headerlink" href="#flask.Flask.cli" title="Link to this definition">¶</a></dt> <dd><p>The Click command group for registering CLI commands for this object. The commands are available from the <code class="docutils literal notranslate"><span class="pre">flask</span></code> command once the application has been discovered and blueprints have been registered.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.get_send_file_max_age"> <span class="sig-name descname"><span class="pre">get_send_file_max_age</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.get_send_file_max_age" title="Link to this definition">¶</a></dt> <dd><p>Used by <a class="reference internal" href="#flask.send_file" title="flask.send_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_file()</span></code></a> to determine the <code class="docutils literal notranslate"><span class="pre">max_age</span></code> cache value for a given file path if it wasn’t passed.</p> <p>By default, this returns <a class="reference internal" href="../config/#SEND_FILE_MAX_AGE_DEFAULT" title="SEND_FILE_MAX_AGE_DEFAULT"><code class="xref py py-data docutils literal notranslate"><span class="pre">SEND_FILE_MAX_AGE_DEFAULT</span></code></a> from the configuration of <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a>. This defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable.</p> <p>Note this is a duplicate of the same method in the Flask class.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The default configuration is <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of 12 hours.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)">int</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.send_static_file"> <span class="sig-name descname"><span class="pre">send_static_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.send_static_file" title="Link to this definition">¶</a></dt> <dd><p>The view function used to serve files from <a class="reference internal" href="#flask.Flask.static_folder" title="flask.Flask.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a>. A route is automatically registered for this view at <a class="reference internal" href="#flask.Flask.static_url_path" title="flask.Flask.static_url_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_url_path</span></code></a> if <a class="reference internal" href="#flask.Flask.static_folder" title="flask.Flask.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a> is set.</p> <p>Note this is a duplicate of the same method in the Flask class.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.open_resource"> <span class="sig-name descname"><span class="pre">open_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rb'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.open_resource" title="Link to this definition">¶</a></dt> <dd><p>Open a resource file relative to <a class="reference internal" href="#flask.Flask.root_path" title="flask.Flask.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a> for reading.</p> <p>For example, if the file <code class="docutils literal notranslate"><span class="pre">schema.sql</span></code> is next to the file <code class="docutils literal notranslate"><span class="pre">app.py</span></code> where the <code class="docutils literal notranslate"><span class="pre">Flask</span></code> app is defined, it can be opened with:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">open_resource</span><span class="p">(</span><span class="s2">&quot;schema.sql&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="n">conn</span><span class="o">.</span><span class="n">executescript</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">())</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>resource</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Path to the resource relative to <a class="reference internal" href="#flask.Flask.root_path" title="flask.Flask.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>.</p></li> <li><p><strong>mode</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Open the file in this mode. Only reading is supported, valid values are <code class="docutils literal notranslate"><span class="pre">&quot;r&quot;</span></code> (or <code class="docutils literal notranslate"><span class="pre">&quot;rt&quot;</span></code>) and <code class="docutils literal notranslate"><span class="pre">&quot;rb&quot;</span></code>.</p></li> <li><p><strong>encoding</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – Open the file with this encoding when opening in text mode. This is ignored when opening in binary mode.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a></p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <code class="docutils literal notranslate"><span class="pre">encoding</span></code> parameter.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.open_instance_resource"> <span class="sig-name descname"><span class="pre">open_instance_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rb'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'utf-8'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.open_instance_resource" title="Link to this definition">¶</a></dt> <dd><p>Open a resource file relative to the application’s instance folder <a class="reference internal" href="#flask.Flask.instance_path" title="flask.Flask.instance_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">instance_path</span></code></a>. Unlike <a class="reference internal" href="#flask.Flask.open_resource" title="flask.Flask.open_resource"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_resource()</span></code></a>, files in the instance folder can be opened for writing.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>resource</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Path to the resource relative to <a class="reference internal" href="#flask.Flask.instance_path" title="flask.Flask.instance_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">instance_path</span></code></a>.</p></li> <li><p><strong>mode</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Open the file in this mode.</p></li> <li><p><strong>encoding</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – Open the file with this encoding when opening in text mode. This is ignored when opening in binary mode.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a></p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <code class="docutils literal notranslate"><span class="pre">encoding</span></code> parameter.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.create_jinja_environment"> <span class="sig-name descname"><span class="pre">create_jinja_environment</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.create_jinja_environment" title="Link to this definition">¶</a></dt> <dd><p>Create the Jinja environment based on <a class="reference internal" href="#flask.Flask.jinja_options" title="flask.Flask.jinja_options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">jinja_options</span></code></a> and the various Jinja-related methods of the app. Changing <a class="reference internal" href="#flask.Flask.jinja_options" title="flask.Flask.jinja_options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">jinja_options</span></code></a> after this will have no effect. Also adds Flask-related globals and filters to the environment.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.11: </span><code class="docutils literal notranslate"><span class="pre">Environment.auto_reload</span></code> set in accordance with <code class="docutils literal notranslate"><span class="pre">TEMPLATES_AUTO_RELOAD</span></code> configuration option.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><em>Environment</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.create_url_adapter"> <span class="sig-name descname"><span class="pre">create_url_adapter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.create_url_adapter" title="Link to this definition">¶</a></dt> <dd><p>Creates a URL adapter for the given request. The URL adapter is created at a point where the request context is not yet set up so the request is passed explicitly.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>If <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a> is set, it does not restrict requests to only that domain, for both <code class="docutils literal notranslate"><span class="pre">subdomain_matching</span></code> and <code class="docutils literal notranslate"><span class="pre">host_matching</span></code>.</p> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span><a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a> no longer implicitly enables subdomain matching. Use <code class="xref py py-attr docutils literal notranslate"><span class="pre">subdomain_matching</span></code> instead.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>This can be called outside a request when the URL adapter is created for an application context.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>request</strong> (<a class="reference internal" href="#flask.Request" title="flask.wrappers.Request"><em>Request</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.MapAdapter" title="(in Werkzeug v3.1.x)"><em>MapAdapter</em></a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.update_template_context"> <span class="sig-name descname"><span class="pre">update_template_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.update_template_context" title="Link to this definition">¶</a></dt> <dd><p>Update the template context with some commonly used variables. This injects request, session, config and g into the template context as well as everything template context processors want to inject. Note that the as of Flask 0.6, the original values in the context will not be overridden if a context processor decides to return a value with the same key.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>context</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>) – the context as a dictionary that is updated in place to add extra variables.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.make_shell_context"> <span class="sig-name descname"><span class="pre">make_shell_context</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.make_shell_context" title="Link to this definition">¶</a></dt> <dd><p>Returns the shell context for an interactive shell for this application. This runs all the registered shell context processors.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)">dict</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.run"> <span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">debug</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_dotenv</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.run" title="Link to this definition">¶</a></dt> <dd><p>Runs the application on a local development server.</p> <p>Do not use <code class="docutils literal notranslate"><span class="pre">run()</span></code> in a production setting. It is not intended to meet security and performance requirements for a production server. Instead, see <a class="reference internal" href="../deploying/"><span class="doc">Deploying to Production</span></a> for WSGI server recommendations.</p> <p>If the <a class="reference internal" href="#flask.Flask.debug" title="flask.Flask.debug"><code class="xref py py-attr docutils literal notranslate"><span class="pre">debug</span></code></a> flag is set the server will automatically reload for code changes and show a debugger in case an exception happened.</p> <p>If you want to run the application in debug mode, but disable the code execution on the interactive debugger, you can pass <code class="docutils literal notranslate"><span class="pre">use_evalex=False</span></code> as parameter. This will keep the debugger’s traceback screen active, but disable code execution.</p> <p>It is not recommended to use this function for development with automatic reloading as this is badly supported. Instead you should be using the <strong class="command">flask</strong> command line script’s <code class="docutils literal notranslate"><span class="pre">run</span></code> support.</p> <div class="admonition-keep-in-mind admonition"> <p class="admonition-title">Keep in Mind</p> <p>Flask will suppress any server error with a generic error page unless it is in debug mode. As such to enable just the interactive debugger without the code reloading, you have to invoke <a class="reference internal" href="#flask.Flask.run" title="flask.Flask.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">debug=True</span></code> and <code class="docutils literal notranslate"><span class="pre">use_reloader=False</span></code>. Setting <code class="docutils literal notranslate"><span class="pre">use_debugger</span></code> to <code class="docutils literal notranslate"><span class="pre">True</span></code> without being in debug mode won’t catch any exceptions because there won’t be any to catch.</p> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>host</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the hostname to listen on. Set this to <code class="docutils literal notranslate"><span class="pre">'0.0.0.0'</span></code> to have the server available externally as well. Defaults to <code class="docutils literal notranslate"><span class="pre">'127.0.0.1'</span></code> or the host in the <code class="docutils literal notranslate"><span class="pre">SERVER_NAME</span></code> config variable if present.</p></li> <li><p><strong>port</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>None</em>) – the port of the webserver. Defaults to <code class="docutils literal notranslate"><span class="pre">5000</span></code> or the port defined in the <code class="docutils literal notranslate"><span class="pre">SERVER_NAME</span></code> config variable if present.</p></li> <li><p><strong>debug</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><em>None</em>) – if given, enable or disable debug mode. See <a class="reference internal" href="#flask.Flask.debug" title="flask.Flask.debug"><code class="xref py py-attr docutils literal notranslate"><span class="pre">debug</span></code></a>.</p></li> <li><p><strong>load_dotenv</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Load the nearest <code class="file docutils literal notranslate"><span class="pre">.env</span></code> and <code class="file docutils literal notranslate"><span class="pre">.flaskenv</span></code> files to set environment variables. Will also change the working directory to the directory containing the first file found.</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – the options to be forwarded to the underlying Werkzeug server. See <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/serving/#werkzeug.serving.run_simple" title="(in Werkzeug v3.1.x)"><code class="xref py py-func docutils literal notranslate"><span class="pre">werkzeug.serving.run_simple()</span></code></a> for more information.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>If installed, python-dotenv will be used to load environment variables from <code class="file docutils literal notranslate"><span class="pre">.env</span></code> and <code class="file docutils literal notranslate"><span class="pre">.flaskenv</span></code> files.</p> <p>The <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">FLASK_DEBUG</span></code> environment variable will override <a class="reference internal" href="#flask.Flask.debug" title="flask.Flask.debug"><code class="xref py py-attr docutils literal notranslate"><span class="pre">debug</span></code></a>.</p> <p>Threaded mode is enabled by default.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.10: </span>The default port is now picked from the <code class="docutils literal notranslate"><span class="pre">SERVER_NAME</span></code> variable.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.test_client"> <span class="sig-name descname"><span class="pre">test_client</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">use_cookies</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.test_client" title="Link to this definition">¶</a></dt> <dd><p>Creates a test client for this application. For information about unit testing head over to <a class="reference internal" href="../testing/"><span class="doc">Testing Flask Applications</span></a>.</p> <p>Note that if you are testing for assertions or exceptions in your application code, you must set <code class="docutils literal notranslate"><span class="pre">app.testing</span> <span class="pre">=</span> <span class="pre">True</span></code> in order for the exceptions to propagate to the test client. Otherwise, the exception will be handled by the application (not visible to the test client) and the only indication of an AssertionError or other exception will be a 500 status code response to the test client. See the <a class="reference internal" href="#flask.Flask.testing" title="flask.Flask.testing"><code class="xref py py-attr docutils literal notranslate"><span class="pre">testing</span></code></a> attribute. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">testing</span> <span class="o">=</span> <span class="kc">True</span> <span class="n">client</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">()</span> </pre></div> </div> <p>The test client can be used in a <code class="docutils literal notranslate"><span class="pre">with</span></code> block to defer the closing down of the context until the end of the <code class="docutils literal notranslate"><span class="pre">with</span></code> block. This is useful if you want to access the context locals for testing:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">()</span> <span class="k">as</span> <span class="n">c</span><span class="p">:</span> <span class="n">rv</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/?vodka=42&#39;</span><span class="p">)</span> <span class="k">assert</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;vodka&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;42&#39;</span> </pre></div> </div> <p>Additionally, you may pass optional keyword arguments that will then be passed to the application’s <a class="reference internal" href="#flask.Flask.test_client_class" title="flask.Flask.test_client_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">test_client_class</span></code></a> constructor. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask.testing</span> <span class="kn">import</span> <span class="n">FlaskClient</span> <span class="k">class</span> <span class="nc">CustomClient</span><span class="p">(</span><span class="n">FlaskClient</span><span class="p">):</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">_authentication</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;authentication&quot;</span><span class="p">)</span> <span class="nb">super</span><span class="p">(</span><span class="n">CustomClient</span><span class="p">,</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client_class</span> <span class="o">=</span> <span class="n">CustomClient</span> <span class="n">client</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">(</span><span class="n">authentication</span><span class="o">=</span><span class="s1">&#39;Basic ....&#39;</span><span class="p">)</span> </pre></div> </div> <p>See <a class="reference internal" href="#flask.testing.FlaskClient" title="flask.testing.FlaskClient"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskClient</span></code></a> for more information.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.11: </span>Added <code class="code docutils literal notranslate"><span class="pre">**kwargs</span></code> to support passing additional keyword arguments to the constructor of <a class="reference internal" href="#flask.Flask.test_client_class" title="flask.Flask.test_client_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">test_client_class</span></code></a>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>The <code class="code docutils literal notranslate"><span class="pre">use_cookies</span></code> parameter was added as well as the ability to override the client to be used by setting the <a class="reference internal" href="#flask.Flask.test_client_class" title="flask.Flask.test_client_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">test_client_class</span></code></a> attribute.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.4: </span>added support for <code class="docutils literal notranslate"><span class="pre">with</span></code> block usage for the client.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>use_cookies</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.testing.FlaskClient" title="flask.testing.FlaskClient">FlaskClient</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.test_cli_runner"> <span class="sig-name descname"><span class="pre">test_cli_runner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.test_cli_runner" title="Link to this definition">¶</a></dt> <dd><p>Create a CLI runner for testing CLI commands. See <a class="reference internal" href="../testing/#testing-cli"><span class="std std-ref">Running Commands with the CLI Runner</span></a>.</p> <p>Returns an instance of <a class="reference internal" href="#flask.Flask.test_cli_runner_class" title="flask.Flask.test_cli_runner_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">test_cli_runner_class</span></code></a>, by default <a class="reference internal" href="#flask.testing.FlaskCliRunner" title="flask.testing.FlaskCliRunner"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskCliRunner</span></code></a>. The Flask app object is passed as the first argument.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 1.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>kwargs</strong> (<em>t.Any</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.testing.FlaskCliRunner" title="flask.testing.FlaskCliRunner">FlaskCliRunner</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.handle_http_exception"> <span class="sig-name descname"><span class="pre">handle_http_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.handle_http_exception" title="Link to this definition">¶</a></dt> <dd><p>Handles an HTTP exception. By default this will invoke the registered error handlers and fall back to returning the exception as response.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0.3: </span><code class="docutils literal notranslate"><span class="pre">RoutingException</span></code>, used internally for actions such as slash redirects during routing, is not passed to error handlers.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>Exceptions are looked up by code <em>and</em> by MRO, so <code class="docutils literal notranslate"><span class="pre">HTTPException</span></code> subclasses can be handled with a catch-all handler for the base <code class="docutils literal notranslate"><span class="pre">HTTPException</span></code>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.3.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>e</strong> (<em>HTTPException</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>HTTPException | ft.ResponseReturnValue</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.handle_user_exception"> <span class="sig-name descname"><span class="pre">handle_user_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.handle_user_exception" title="Link to this definition">¶</a></dt> <dd><p>This method is called whenever an exception occurs that should be handled. A special case is <code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPException</span></code> which is forwarded to the <a class="reference internal" href="#flask.Flask.handle_http_exception" title="flask.Flask.handle_http_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_http_exception()</span></code></a> method. This function will either return a response value or reraise the exception with the same traceback.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>Key errors raised from request data like <code class="docutils literal notranslate"><span class="pre">form</span></code> show the bad key in debug mode rather than a generic bad request message.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>e</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>HTTPException | ft.ResponseReturnValue</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.handle_exception"> <span class="sig-name descname"><span class="pre">handle_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.handle_exception" title="Link to this definition">¶</a></dt> <dd><p>Handle an exception that did not have an error handler associated with it, or that was raised from an error handler. This always causes a 500 <code class="docutils literal notranslate"><span class="pre">InternalServerError</span></code>.</p> <p>Always sends the <a class="reference internal" href="#flask.got_request_exception" title="flask.got_request_exception"><code class="xref py py-data docutils literal notranslate"><span class="pre">got_request_exception</span></code></a> signal.</p> <p>If <a class="reference internal" href="../config/#PROPAGATE_EXCEPTIONS" title="PROPAGATE_EXCEPTIONS"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROPAGATE_EXCEPTIONS</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, such as in debug mode, the error will be re-raised so that the debugger can display it. Otherwise, the original exception is logged, and an <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.InternalServerError" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InternalServerError</span></code></a> is returned.</p> <p>If an error handler is registered for <code class="docutils literal notranslate"><span class="pre">InternalServerError</span></code> or <code class="docutils literal notranslate"><span class="pre">500</span></code>, it will be used. For consistency, the handler will always receive the <code class="docutils literal notranslate"><span class="pre">InternalServerError</span></code>. The original unhandled exception is available as <code class="docutils literal notranslate"><span class="pre">e.original_exception</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1.0: </span>Always passes the <code class="docutils literal notranslate"><span class="pre">InternalServerError</span></code> instance to the handler, setting <code class="docutils literal notranslate"><span class="pre">original_exception</span></code> to the unhandled error.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1.0: </span><code class="docutils literal notranslate"><span class="pre">after_request</span></code> functions and other finalization is done even for the default 500 response when there is no handler.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.3.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>e</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.log_exception"> <span class="sig-name descname"><span class="pre">log_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc_info</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.log_exception" title="Link to this definition">¶</a></dt> <dd><p>Logs an exception. This is called by <a class="reference internal" href="#flask.Flask.handle_exception" title="flask.Flask.handle_exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_exception()</span></code></a> if debugging is disabled and right before the handler is called. The default implementation logs the exception as error on the <a class="reference internal" href="#flask.Flask.logger" title="flask.Flask.logger"><code class="xref py py-attr docutils literal notranslate"><span class="pre">logger</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>exc_info</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)"><em>tuple</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/types.html#types.TracebackType" title="(in Python v3.13)"><em>TracebackType</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)"><em>tuple</em></a><em>[</em><em>None</em><em>, </em><em>None</em><em>, </em><em>None</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.dispatch_request"> <span class="sig-name descname"><span class="pre">dispatch_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.dispatch_request" title="Link to this definition">¶</a></dt> <dd><p>Does the request dispatching. Matches the URL and returns the return value of the view or error handler. This does not have to be a response object. In order to convert the return value to a proper response object, call <a class="reference internal" href="#flask.make_response" title="flask.make_response"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_response()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.7: </span>This no longer does the exception handling, this code was moved to the new <a class="reference internal" href="#flask.Flask.full_dispatch_request" title="flask.Flask.full_dispatch_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">full_dispatch_request()</span></code></a>.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>ft.ResponseReturnValue</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.full_dispatch_request"> <span class="sig-name descname"><span class="pre">full_dispatch_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.full_dispatch_request" title="Link to this definition">¶</a></dt> <dd><p>Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.make_default_options_response"> <span class="sig-name descname"><span class="pre">make_default_options_response</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.make_default_options_response" title="Link to this definition">¶</a></dt> <dd><p>This method is called to create the default <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> response. This can be changed through subclassing to change the default behavior of <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> responses.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.ensure_sync"> <span class="sig-name descname"><span class="pre">ensure_sync</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.ensure_sync" title="Link to this definition">¶</a></dt> <dd><p>Ensure that the function is synchronous for WSGI workers. Plain <code class="docutils literal notranslate"><span class="pre">def</span></code> functions are returned as-is. <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code> functions are wrapped to run and wait for the response.</p> <p>Override this method to change how the app runs async views.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>func</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[…], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.async_to_sync"> <span class="sig-name descname"><span class="pre">async_to_sync</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.async_to_sync" title="Link to this definition">¶</a></dt> <dd><p>Return a sync function that will run the coroutine function.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">async_to_sync</span><span class="p">(</span><span class="n">func</span><span class="p">)(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> </pre></div> </div> <p>Override this method to change how the app converts async code to be synchronously callable.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>func</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Coroutine" title="(in Python v3.13)"><em>Coroutine</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[…], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.url_for"> <span class="sig-name descname"><span class="pre">url_for</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_anchor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_scheme</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_external</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">values</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.url_for" title="Link to this definition">¶</a></dt> <dd><p>Generate a URL to the given endpoint with the given values.</p> <p>This is called by <a class="reference internal" href="#flask.url_for" title="flask.url_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">flask.url_for()</span></code></a>, and can be called directly as well.</p> <p>An <em>endpoint</em> is the name of a URL rule, usually added with <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">&#64;app.route()</span></code></a>, and usually the same name as the view function. A route defined in a <a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Blueprint</span></code></a> will prepend the blueprint’s name separated by a <code class="docutils literal notranslate"><span class="pre">.</span></code> to the endpoint.</p> <p>In some cases, such as email messages, you want URLs to include the scheme and domain, like <code class="docutils literal notranslate"><span class="pre">https://example.com/hello</span></code>. When not in an active request, URLs will be external by default, but this requires setting <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a> so Flask knows what domain to use. <a class="reference internal" href="../config/#APPLICATION_ROOT" title="APPLICATION_ROOT"><code class="xref py py-data docutils literal notranslate"><span class="pre">APPLICATION_ROOT</span></code></a> and <a class="reference internal" href="../config/#PREFERRED_URL_SCHEME" title="PREFERRED_URL_SCHEME"><code class="xref py py-data docutils literal notranslate"><span class="pre">PREFERRED_URL_SCHEME</span></code></a> should also be configured as needed. This config is only used when not in an active request.</p> <p>Functions can be decorated with <a class="reference internal" href="#flask.Flask.url_defaults" title="flask.Flask.url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_defaults()</span></code></a> to modify keyword arguments before the URL is built.</p> <p>If building fails for some reason, such as an unknown endpoint or incorrect values, the app’s <a class="reference internal" href="#flask.Flask.handle_url_build_error" title="flask.Flask.handle_url_build_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_url_build_error()</span></code></a> method is called. If that returns a string, that is returned, otherwise a <code class="xref py py-exc docutils literal notranslate"><span class="pre">BuildError</span></code> is raised.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The endpoint name associated with the URL to generate. If this starts with a <code class="docutils literal notranslate"><span class="pre">.</span></code>, the current blueprint name (if any) will be used.</p></li> <li><p><strong>_anchor</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, append this as <code class="docutils literal notranslate"><span class="pre">#anchor</span></code> to the URL.</p></li> <li><p><strong>_method</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, generate the URL associated with this method for the endpoint.</p></li> <li><p><strong>_scheme</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, the URL will have this scheme if it is external.</p></li> <li><p><strong>_external</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><em>None</em>) – If given, prefer the URL to be internal (False) or require it to be external (True). External URLs include the scheme and domain. When not in an active request, URLs are external by default.</p></li> <li><p><strong>values</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Values to use for the variable parts of the URL rule. Unknown keys are appended as query string arguments, like <code class="docutils literal notranslate"><span class="pre">?a=b&amp;c=d</span></code>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2: </span>Moved from <code class="docutils literal notranslate"><span class="pre">flask.url_for</span></code>, which calls this method.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.make_response"> <span class="sig-name descname"><span class="pre">make_response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rv</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.make_response" title="Link to this definition">¶</a></dt> <dd><p>Convert the return value from a view function to an instance of <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>rv</strong> (<em>ft.ResponseReturnValue</em>) – <p>the return value from the view function. The view function must return a response. Returning <code class="docutils literal notranslate"><span class="pre">None</span></code>, or the view ending without returning, is not allowed. The following types are allowed for <code class="docutils literal notranslate"><span class="pre">view_rv</span></code>:</p> <dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">str</span></code></dt><dd><p>A response object is created with the string encoded to UTF-8 as the body.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">bytes</span></code></dt><dd><p>A response object is created with the bytes as the body.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">dict</span></code></dt><dd><p>A dictionary that will be jsonify’d before being returned.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">list</span></code></dt><dd><p>A list that will be jsonify’d before being returned.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">generator</span></code> or <code class="docutils literal notranslate"><span class="pre">iterator</span></code></dt><dd><p>A generator that returns <code class="docutils literal notranslate"><span class="pre">str</span></code> or <code class="docutils literal notranslate"><span class="pre">bytes</span></code> to be streamed as the response.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">tuple</span></code></dt><dd><p>Either <code class="docutils literal notranslate"><span class="pre">(body,</span> <span class="pre">status,</span> <span class="pre">headers)</span></code>, <code class="docutils literal notranslate"><span class="pre">(body,</span> <span class="pre">status)</span></code>, or <code class="docutils literal notranslate"><span class="pre">(body,</span> <span class="pre">headers)</span></code>, where <code class="docutils literal notranslate"><span class="pre">body</span></code> is any of the other types allowed here, <code class="docutils literal notranslate"><span class="pre">status</span></code> is a string or an integer, and <code class="docutils literal notranslate"><span class="pre">headers</span></code> is a dictionary or a list of <code class="docutils literal notranslate"><span class="pre">(key,</span> <span class="pre">value)</span></code> tuples. If <code class="docutils literal notranslate"><span class="pre">body</span></code> is a <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a> instance, <code class="docutils literal notranslate"><span class="pre">status</span></code> overwrites the exiting value and <code class="docutils literal notranslate"><span class="pre">headers</span></code> are extended.</p> </dd> <dt><a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a></dt><dd><p>The object is returned unchanged.</p> </dd> <dt>other <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Response" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> class</dt><dd><p>The object is coerced to <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a>.</p> </dd> <dt><a class="reference external" href="https://docs.python.org/3/library/functions.html#callable" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">callable()</span></code></a></dt><dd><p>The function is called as a WSGI application. The result is used to create a response object.</p> </dd> </dl> </p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>A generator will be converted to a streaming response. A list will be converted to a JSON response.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1: </span>A dict will be converted to a JSON response.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>Previously a tuple was interpreted as the arguments for the response object.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.preprocess_request"> <span class="sig-name descname"><span class="pre">preprocess_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.preprocess_request" title="Link to this definition">¶</a></dt> <dd><p>Called before the request is dispatched. Calls <a class="reference internal" href="#flask.Flask.url_value_preprocessors" title="flask.Flask.url_value_preprocessors"><code class="xref py py-attr docutils literal notranslate"><span class="pre">url_value_preprocessors</span></code></a> registered with the app and the current blueprint (if any). Then calls <a class="reference internal" href="#flask.Flask.before_request_funcs" title="flask.Flask.before_request_funcs"><code class="xref py py-attr docutils literal notranslate"><span class="pre">before_request_funcs</span></code></a> registered with the app and the blueprint.</p> <p>If any <a class="reference internal" href="#flask.Flask.before_request" title="flask.Flask.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a> handler returns a non-None value, the value is handled as if it was the return value from the view, and further request handling is stopped.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>ft.ResponseReturnValue | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.process_response"> <span class="sig-name descname"><span class="pre">process_response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.process_response" title="Link to this definition">¶</a></dt> <dd><p>Can be overridden in order to modify the response object before it’s sent to the WSGI server. By default this will call all the <a class="reference internal" href="#flask.Flask.after_request" title="flask.Flask.after_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">after_request()</span></code></a> decorated functions.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.5: </span>As of Flask 0.5 the functions registered for after request execution are called in reverse order of registration.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>response</strong> (<a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a>) – a <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a> object.</p> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a new response object or the same, has to be an instance of <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a>.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.wrappers.Response"><em>Response</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.do_teardown_request"> <span class="sig-name descname"><span class="pre">do_teardown_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.do_teardown_request" title="Link to this definition">¶</a></dt> <dd><p>Called after the request is dispatched and the response is returned, right before the request context is popped.</p> <p>This calls all functions decorated with <a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a>, and <a class="reference internal" href="#flask.Blueprint.teardown_request" title="flask.Blueprint.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.teardown_request()</span></code></a> if a blueprint handled the request. Finally, the <a class="reference internal" href="#flask.request_tearing_down" title="flask.request_tearing_down"><code class="xref py py-data docutils literal notranslate"><span class="pre">request_tearing_down</span></code></a> signal is sent.</p> <p>This is called by <a class="reference internal" href="#flask.ctx.RequestContext.pop" title="flask.ctx.RequestContext.pop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RequestContext.pop()</span></code></a>, which may be delayed during testing to maintain access to resources.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>exc</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em> | </em><em>None</em>) – An unhandled exception raised while dispatching the request. Detected from the current exception information if not passed. Passed to each teardown function.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>Added the <code class="docutils literal notranslate"><span class="pre">exc</span></code> argument.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.do_teardown_appcontext"> <span class="sig-name descname"><span class="pre">do_teardown_appcontext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.do_teardown_appcontext" title="Link to this definition">¶</a></dt> <dd><p>Called right before the application context is popped.</p> <p>When handling a request, the application context is popped after the request context. See <a class="reference internal" href="#flask.Flask.do_teardown_request" title="flask.Flask.do_teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">do_teardown_request()</span></code></a>.</p> <p>This calls all functions decorated with <a class="reference internal" href="#flask.Flask.teardown_appcontext" title="flask.Flask.teardown_appcontext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_appcontext()</span></code></a>. Then the <a class="reference internal" href="#flask.appcontext_tearing_down" title="flask.appcontext_tearing_down"><code class="xref py py-data docutils literal notranslate"><span class="pre">appcontext_tearing_down</span></code></a> signal is sent.</p> <p>This is called by <a class="reference internal" href="#flask.ctx.AppContext.pop" title="flask.ctx.AppContext.pop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AppContext.pop()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>exc</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.app_context"> <span class="sig-name descname"><span class="pre">app_context</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.app_context" title="Link to this definition">¶</a></dt> <dd><p>Create an <a class="reference internal" href="#flask.ctx.AppContext" title="flask.ctx.AppContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppContext</span></code></a>. Use as a <code class="docutils literal notranslate"><span class="pre">with</span></code> block to push the context, which will make <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> point at this application.</p> <p>An application context is automatically pushed by <code class="xref py py-meth docutils literal notranslate"><span class="pre">RequestContext.push()</span></code> when handling a request, and when running a CLI command. Use this to manually create a context outside of these situations.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">app_context</span><span class="p">():</span> <span class="n">init_db</span><span class="p">()</span> </pre></div> </div> <p>See <a class="reference internal" href="../appcontext/"><span class="doc">The Application Context</span></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.ctx.AppContext" title="flask.ctx.AppContext"><em>AppContext</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.request_context"> <span class="sig-name descname"><span class="pre">request_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.request_context" title="Link to this definition">¶</a></dt> <dd><p>Create a <a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestContext</span></code></a> representing a WSGI environment. Use a <code class="docutils literal notranslate"><span class="pre">with</span></code> block to push the context, which will make <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-data docutils literal notranslate"><span class="pre">request</span></code></a> point at this request.</p> <p>See <a class="reference internal" href="../reqcontext/"><span class="doc">The Request Context</span></a>.</p> <p>Typically you should not call this from your own code. A request context is automatically pushed by the <a class="reference internal" href="#flask.Flask.wsgi_app" title="flask.Flask.wsgi_app"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wsgi_app()</span></code></a> when handling a request. Use <a class="reference internal" href="#flask.Flask.test_request_context" title="flask.Flask.test_request_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_request_context()</span></code></a> to create an environment and context instead of this method.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – a WSGI environment</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext">RequestContext</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.test_request_context"> <span class="sig-name descname"><span class="pre">test_request_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.test_request_context" title="Link to this definition">¶</a></dt> <dd><p>Create a <a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestContext</span></code></a> for a WSGI environment created from the given values. This is mostly useful during testing, where you may want to run a function that uses request data without dispatching a full request.</p> <p>See <a class="reference internal" href="../reqcontext/"><span class="doc">The Request Context</span></a>.</p> <p>Use a <code class="docutils literal notranslate"><span class="pre">with</span></code> block to push the context, which will make <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-data docutils literal notranslate"><span class="pre">request</span></code></a> point at the request for the created environment.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">test_request_context</span><span class="p">(</span><span class="o">...</span><span class="p">):</span> <span class="n">generate_report</span><span class="p">()</span> </pre></div> </div> <p>When using the shell, it may be easier to push and pop the context manually to avoid indentation.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_request_context</span><span class="p">(</span><span class="o">...</span><span class="p">)</span> <span class="n">ctx</span><span class="o">.</span><span class="n">push</span><span class="p">()</span> <span class="o">...</span> <span class="n">ctx</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span> </pre></div> </div> <p>Takes the same arguments as Werkzeug’s <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.EnvironBuilder" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code></a>, with some defaults from the application. See the linked Werkzeug docs for most of the available arguments. Flask-specific behavior is listed here.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>path</strong> – URL path being requested.</p></li> <li><p><strong>base_url</strong> – Base URL where the app is being served, which <code class="docutils literal notranslate"><span class="pre">path</span></code> is relative to. If not given, built from <a class="reference internal" href="../config/#PREFERRED_URL_SCHEME" title="PREFERRED_URL_SCHEME"><code class="xref py py-data docutils literal notranslate"><span class="pre">PREFERRED_URL_SCHEME</span></code></a>, <code class="docutils literal notranslate"><span class="pre">subdomain</span></code>, <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a>, and <a class="reference internal" href="../config/#APPLICATION_ROOT" title="APPLICATION_ROOT"><code class="xref py py-data docutils literal notranslate"><span class="pre">APPLICATION_ROOT</span></code></a>.</p></li> <li><p><strong>subdomain</strong> – Subdomain name to append to <a class="reference internal" href="../config/#SERVER_NAME" title="SERVER_NAME"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_NAME</span></code></a>.</p></li> <li><p><strong>url_scheme</strong> – Scheme to use instead of <a class="reference internal" href="../config/#PREFERRED_URL_SCHEME" title="PREFERRED_URL_SCHEME"><code class="xref py py-data docutils literal notranslate"><span class="pre">PREFERRED_URL_SCHEME</span></code></a>.</p></li> <li><p><strong>data</strong> – The request body, either as a string or a dict of form keys and values.</p></li> <li><p><strong>json</strong> – If given, this is serialized as JSON and passed as <code class="docutils literal notranslate"><span class="pre">data</span></code>. Also defaults <code class="docutils literal notranslate"><span class="pre">content_type</span></code> to <code class="docutils literal notranslate"><span class="pre">application/json</span></code>.</p></li> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – other positional arguments passed to <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.EnvironBuilder" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code></a>.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – other keyword arguments passed to <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.EnvironBuilder" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><em>RequestContext</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.wsgi_app"> <span class="sig-name descname"><span class="pre">wsgi_app</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.wsgi_app" title="Link to this definition">¶</a></dt> <dd><p>The actual WSGI application. This is not implemented in <code class="xref py py-meth docutils literal notranslate"><span class="pre">__call__()</span></code> so that middlewares can be applied without losing a reference to the app object. Instead of doing this:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">MyMiddleware</span><span class="p">(</span><span class="n">app</span><span class="p">)</span> </pre></div> </div> <p>It’s a better idea to do this instead:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">wsgi_app</span> <span class="o">=</span> <span class="n">MyMiddleware</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">wsgi_app</span><span class="p">)</span> </pre></div> </div> <p>Then you still have the original application object around and can continue to call methods on it.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.7: </span>Teardown events for the request and app contexts are called even if an unhandled error occurs. Other events may not be called depending on when an error occurs during dispatch. See <a class="reference internal" href="../reqcontext/#callbacks-and-errors"><span class="std std-ref">Callbacks and Errors</span></a>.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – A WSGI environment.</p></li> <li><p><strong>start_response</strong> (<em>StartResponse</em>) – A callable accepting a status code, a list of headers, and an optional exception context to start the response.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>cabc.Iterable[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a>]</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.aborter_class"> <span class="sig-name descname"><span class="pre">aborter_class</span></span><a class="headerlink" href="#flask.Flask.aborter_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.Aborter" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Aborter</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.add_template_filter"> <span class="sig-name descname"><span class="pre">add_template_filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.add_template_filter" title="Link to this definition">¶</a></dt> <dd><p>Register a custom template filter. Works exactly like the <a class="reference internal" href="#flask.Flask.template_filter" title="flask.Flask.template_filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">template_filter()</span></code></a> decorator.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the filter, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.add_template_global"> <span class="sig-name descname"><span class="pre">add_template_global</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.add_template_global" title="Link to this definition">¶</a></dt> <dd><p>Register a custom template global function. Works exactly like the <a class="reference internal" href="#flask.Flask.template_global" title="flask.Flask.template_global"><code class="xref py py-meth docutils literal notranslate"><span class="pre">template_global()</span></code></a> decorator.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the global function, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.add_template_test"> <span class="sig-name descname"><span class="pre">add_template_test</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.add_template_test" title="Link to this definition">¶</a></dt> <dd><p>Register a custom template test. Works exactly like the <a class="reference internal" href="#flask.Flask.template_test" title="flask.Flask.template_test"><code class="xref py py-meth docutils literal notranslate"><span class="pre">template_test()</span></code></a> decorator.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the test, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.add_url_rule"> <span class="sig-name descname"><span class="pre">add_url_rule</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">endpoint</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">view_func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">provide_automatic_options</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.add_url_rule" title="Link to this definition">¶</a></dt> <dd><p>Register a rule for routing incoming requests and building URLs. The <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> decorator is a shortcut to call this with the <code class="docutils literal notranslate"><span class="pre">view_func</span></code> argument. These are equivalent:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="o">...</span> <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="n">index</span><span class="p">)</span> </pre></div> </div> <p>See <a class="reference internal" href="#url-route-registrations"><span class="std std-ref">URL Route Registrations</span></a>.</p> <p>The endpoint name for the route defaults to the name of the view function if the <code class="docutils literal notranslate"><span class="pre">endpoint</span></code> parameter isn’t passed. An error will be raised if a function has already been registered for the endpoint.</p> <p>The <code class="docutils literal notranslate"><span class="pre">methods</span></code> parameter defaults to <code class="docutils literal notranslate"><span class="pre">[&quot;GET&quot;]</span></code>. <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> is always added automatically, and <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> is added automatically by default.</p> <p><code class="docutils literal notranslate"><span class="pre">view_func</span></code> does not necessarily need to be passed, but if the rule should participate in routing an endpoint name must be associated with a view function at some point with the <a class="reference internal" href="#flask.Flask.endpoint" title="flask.Flask.endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endpoint()</span></code></a> decorator.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="s2">&quot;index&quot;</span><span class="p">)</span> <span class="nd">@app</span><span class="o">.</span><span class="n">endpoint</span><span class="p">(</span><span class="s2">&quot;index&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <p>If <code class="docutils literal notranslate"><span class="pre">view_func</span></code> has a <code class="docutils literal notranslate"><span class="pre">required_methods</span></code> attribute, those methods are added to the passed and automatic methods. If it has a <code class="docutils literal notranslate"><span class="pre">provide_automatic_methods</span></code> attribute, it is used as the default if the parameter is not passed.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The URL rule string.</p></li> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – The endpoint name to associate with the rule and view function. Used when routing and building URLs. Defaults to <code class="docutils literal notranslate"><span class="pre">view_func.__name__</span></code>.</p></li> <li><p><strong>view_func</strong> (<em>ft.RouteCallable</em><em> | </em><em>None</em>) – The view function to associate with the endpoint name.</p></li> <li><p><strong>provide_automatic_options</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><em>None</em>) – Add the <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> method and respond to <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> requests automatically.</p></li> <li><p><strong>options</strong> (<em>t.Any</em>) – Extra options passed to the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Rule" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a> object.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.after_request"> <span class="sig-name descname"><span class="pre">after_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.after_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to run after each request to this object.</p> <p>The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent.</p> <p>If a function raises an exception, any remaining <code class="docutils literal notranslate"><span class="pre">after_request</span></code> functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use <a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a> for that.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes after every request. When used on a blueprint, this executes after every request that the blueprint handles. To register with a blueprint and execute after every request, use <a class="reference internal" href="#flask.Blueprint.after_app_request" title="flask.Blueprint.after_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.after_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_after_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_after_request</em></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.app_ctx_globals_class"> <span class="sig-name descname"><span class="pre">app_ctx_globals_class</span></span><a class="headerlink" href="#flask.Flask.app_ctx_globals_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.ctx._AppCtxGlobals" title="flask.ctx._AppCtxGlobals"><code class="xref py py-class docutils literal notranslate"><span class="pre">_AppCtxGlobals</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.auto_find_instance_path"> <span class="sig-name descname"><span class="pre">auto_find_instance_path</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.auto_find_instance_path" title="Link to this definition">¶</a></dt> <dd><p>Tries to locate the instance path if it was not provided to the constructor of the application class. It will basically calculate the path to a folder named <code class="docutils literal notranslate"><span class="pre">instance</span></code> next to your main file or the package.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.before_request"> <span class="sig-name descname"><span class="pre">before_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.before_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to run before each request.</p> <p>For example, this can be used to open a database connection, or to load the logged in user from the session.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">before_request</span> <span class="k">def</span> <span class="nf">load_user</span><span class="p">():</span> <span class="k">if</span> <span class="s2">&quot;user_id&quot;</span> <span class="ow">in</span> <span class="n">session</span><span class="p">:</span> <span class="n">g</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">])</span> </pre></div> </div> <p>The function will be called without any arguments. If it returns a non-<code class="docutils literal notranslate"><span class="pre">None</span></code> value, the value is handled as if it was the return value from the view, and further request handling is stopped.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes before every request. When used on a blueprint, this executes before every request that the blueprint handles. To register with a blueprint and execute before every request, use <a class="reference internal" href="#flask.Blueprint.before_app_request" title="flask.Blueprint.before_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.before_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_before_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_before_request</em></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.config_class"> <span class="sig-name descname"><span class="pre">config_class</span></span><a class="headerlink" href="#flask.Flask.config_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.Config" title="flask.config.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.context_processor"> <span class="sig-name descname"><span class="pre">context_processor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.context_processor" title="Link to this definition">¶</a></dt> <dd><p>Registers a template context processor function. These functions run before rendering a template. The keys of the returned dict are added as variables available in the template.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every rendered template. When used on a blueprint, this is called for templates rendered from the blueprint’s views. To register with a blueprint and affect every template, use <a class="reference internal" href="#flask.Blueprint.app_context_processor" title="flask.Blueprint.app_context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_context_processor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_template_context_processor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_template_context_processor</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.create_global_jinja_loader"> <span class="sig-name descname"><span class="pre">create_global_jinja_loader</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.create_global_jinja_loader" title="Link to this definition">¶</a></dt> <dd><p>Creates the loader for the Jinja2 environment. Can be used to override just the loader and keeping the rest unchanged. It’s discouraged to override this function. Instead one should override the <a class="reference internal" href="#flask.Flask.jinja_loader" title="flask.Flask.jinja_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">jinja_loader()</span></code></a> function instead.</p> <p>The global loader dispatches between the loaders of the application and the individual blueprints.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><em>DispatchingJinjaLoader</em></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.debug"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">debug</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Flask.debug" title="Link to this definition">¶</a></dt> <dd><p>Whether debug mode is enabled. When using <code class="docutils literal notranslate"><span class="pre">flask</span> <span class="pre">run</span></code> to start the development server, an interactive debugger will be shown for unhandled exceptions, and the server will be reloaded when code changes. This maps to the <a class="reference internal" href="../config/#DEBUG" title="DEBUG"><code class="xref py py-data docutils literal notranslate"><span class="pre">DEBUG</span></code></a> config key. It may not behave as expected if set late.</p> <p><strong>Do not enable debug mode when deploying in production.</strong></p> <p>Default: <code class="docutils literal notranslate"><span class="pre">False</span></code></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.delete"> <span class="sig-name descname"><span class="pre">delete</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.delete" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;DELETE&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.endpoint"> <span class="sig-name descname"><span class="pre">endpoint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.endpoint" title="Link to this definition">¶</a></dt> <dd><p>Decorate a view function to register it for the given endpoint. Used if a rule is added without a <code class="docutils literal notranslate"><span class="pre">view_func</span></code> with <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a>.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s2">&quot;/ex&quot;</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="s2">&quot;example&quot;</span><span class="p">)</span> <span class="nd">@app</span><span class="o">.</span><span class="n">endpoint</span><span class="p">(</span><span class="s2">&quot;example&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">example</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The endpoint name to associate with the view function.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>F</em>], <em>F</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.errorhandler"> <span class="sig-name descname"><span class="pre">errorhandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code_or_exception</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.errorhandler" title="Link to this definition">¶</a></dt> <dd><p>Register a function to handle errors by code or exception class.</p> <p>A decorator that is used to register a function given an error code. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="mi">404</span><span class="p">)</span> <span class="k">def</span> <span class="nf">page_not_found</span><span class="p">(</span><span class="n">error</span><span class="p">):</span> <span class="k">return</span> <span class="s1">&#39;This page does not exist&#39;</span><span class="p">,</span> <span class="mi">404</span> </pre></div> </div> <p>You can also register handlers for arbitrary exceptions:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="n">DatabaseError</span><span class="p">)</span> <span class="k">def</span> <span class="nf">special_exception_handler</span><span class="p">(</span><span class="n">error</span><span class="p">):</span> <span class="k">return</span> <span class="s1">&#39;Database connection failed&#39;</span><span class="p">,</span> <span class="mi">500</span> </pre></div> </div> <p>This is available on both app and blueprint objects. When used on an app, this can handle errors from every request. When used on a blueprint, this can handle errors from requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_errorhandler" title="flask.Blueprint.app_errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_errorhandler()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>Use <a class="reference internal" href="#flask.Flask.register_error_handler" title="flask.Flask.register_error_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_error_handler()</span></code></a> instead of modifying <a class="reference internal" href="#flask.Flask.error_handler_spec" title="flask.Flask.error_handler_spec"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_handler_spec</span></code></a> directly, for application wide error handlers.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>One can now additionally also register custom exception types that do not necessarily have to be a subclass of the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.HTTPException" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPException</span></code></a> class.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>code_or_exception</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – the code as integer for the handler, or an arbitrary exception</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_error_handler</em>], <em>T_error_handler</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.get"> <span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.get" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;GET&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.handle_url_build_error"> <span class="sig-name descname"><span class="pre">handle_url_build_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">error</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">values</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.handle_url_build_error" title="Link to this definition">¶</a></dt> <dd><p>Called by <a class="reference internal" href="#flask.Flask.url_for" title="flask.Flask.url_for"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_for()</span></code></a> if a <code class="xref py py-exc docutils literal notranslate"><span class="pre">BuildError</span></code> was raised. If this returns a value, it will be returned by <code class="docutils literal notranslate"><span class="pre">url_for</span></code>, otherwise the error will be re-raised.</p> <p>Each function in <a class="reference internal" href="#flask.Flask.url_build_error_handlers" title="flask.Flask.url_build_error_handlers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">url_build_error_handlers</span></code></a> is called with <code class="docutils literal notranslate"><span class="pre">error</span></code>, <code class="docutils literal notranslate"><span class="pre">endpoint</span></code> and <code class="docutils literal notranslate"><span class="pre">values</span></code>. If a function returns <code class="docutils literal notranslate"><span class="pre">None</span></code> or raises a <code class="docutils literal notranslate"><span class="pre">BuildError</span></code>, it is skipped. Otherwise, its return value is returned by <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>error</strong> (<em>BuildError</em>) – The active <code class="docutils literal notranslate"><span class="pre">BuildError</span></code> being handled.</p></li> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The endpoint being built.</p></li> <li><p><strong>values</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>) – The keyword arguments passed to <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.has_static_folder"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">has_static_folder</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Flask.has_static_folder" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if <a class="reference internal" href="#flask.Flask.static_folder" title="flask.Flask.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a> is set.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.inject_url_defaults"> <span class="sig-name descname"><span class="pre">inject_url_defaults</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">values</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.inject_url_defaults" title="Link to this definition">¶</a></dt> <dd><p>Injects the URL defaults for the given endpoint directly into the values dictionary passed. This is used internally and automatically called on URL building.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>values</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.iter_blueprints"> <span class="sig-name descname"><span class="pre">iter_blueprints</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.iter_blueprints" title="Link to this definition">¶</a></dt> <dd><p>Iterates over all blueprints by the order they were registered.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>t.ValuesView[<a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint">Blueprint</a>]</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.jinja_env"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">jinja_env</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Environment</span></em><a class="headerlink" href="#flask.Flask.jinja_env" title="Link to this definition">¶</a></dt> <dd><p>The Jinja environment used to load templates.</p> <p>The environment is created the first time this property is accessed. Changing <a class="reference internal" href="#flask.Flask.jinja_options" title="flask.Flask.jinja_options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">jinja_options</span></code></a> after that will have no effect.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.jinja_environment"> <span class="sig-name descname"><span class="pre">jinja_environment</span></span><a class="headerlink" href="#flask.Flask.jinja_environment" title="Link to this definition">¶</a></dt> <dd><p>alias of <code class="xref py py-class docutils literal notranslate"><span class="pre">Environment</span></code></p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.jinja_loader"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">jinja_loader</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.BaseLoader" title="(in Jinja v3.1.x)"><span class="pre">BaseLoader</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Flask.jinja_loader" title="Link to this definition">¶</a></dt> <dd><p>The Jinja loader for this object’s templates. By default this is a class <a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.FileSystemLoader" title="(in Jinja v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">jinja2.loaders.FileSystemLoader</span></code></a> to <a class="reference internal" href="#flask.Flask.template_folder" title="flask.Flask.template_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">template_folder</span></code></a> if it is set.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.jinja_options"> <span class="sig-name descname"><span class="pre">jinja_options</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{}</span></em><a class="headerlink" href="#flask.Flask.jinja_options" title="Link to this definition">¶</a></dt> <dd><p>Options that are passed to the Jinja environment in <a class="reference internal" href="#flask.Flask.create_jinja_environment" title="flask.Flask.create_jinja_environment"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_jinja_environment()</span></code></a>. Changing these options after the environment is created (accessing <a class="reference internal" href="#flask.Flask.jinja_env" title="flask.Flask.jinja_env"><code class="xref py py-attr docutils literal notranslate"><span class="pre">jinja_env</span></code></a>) will have no effect.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1.0: </span>This is a <code class="docutils literal notranslate"><span class="pre">dict</span></code> instead of an <code class="docutils literal notranslate"><span class="pre">ImmutableDict</span></code> to allow easier configuration.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.json_provider_class"> <span class="sig-name descname"><span class="pre">json_provider_class</span></span><a class="headerlink" href="#flask.Flask.json_provider_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider" title="flask.json.provider.DefaultJSONProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">DefaultJSONProvider</span></code></a></p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.logger"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">logger</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/logging.html#logging.Logger" title="(in Python v3.13)"><span class="pre">Logger</span></a></em><a class="headerlink" href="#flask.Flask.logger" title="Link to this definition">¶</a></dt> <dd><p>A standard Python <a class="reference external" href="https://docs.python.org/3/library/logging.html#logging.Logger" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> for the app, with the same name as <a class="reference internal" href="#flask.Flask.name" title="flask.Flask.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a>.</p> <p>In debug mode, the logger’s <a class="reference external" href="https://docs.python.org/3/library/logging.html#logging.Logger.level" title="(in Python v3.13)"><code class="xref py py-attr docutils literal notranslate"><span class="pre">level</span></code></a> will be set to <a class="reference external" href="https://docs.python.org/3/library/logging.html#logging.DEBUG" title="(in Python v3.13)"><code class="xref py py-data docutils literal notranslate"><span class="pre">DEBUG</span></code></a>.</p> <p>If there are no handlers configured, a default handler will be added. See <a class="reference internal" href="../logging/"><span class="doc">Logging</span></a> for more information.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1.0: </span>The logger takes the same name as <a class="reference internal" href="#flask.Flask.name" title="flask.Flask.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> rather than hard-coding <code class="docutils literal notranslate"><span class="pre">&quot;flask.app&quot;</span></code>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0.0: </span>Behavior was simplified. The logger is always named <code class="docutils literal notranslate"><span class="pre">&quot;flask.app&quot;</span></code>. The level is only set during configuration, it doesn’t check <code class="docutils literal notranslate"><span class="pre">app.debug</span></code> each time. Only one format is used, not different ones depending on <code class="docutils literal notranslate"><span class="pre">app.debug</span></code>. No handlers are removed, and a handler is only added if no handlers are already configured.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.3.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.make_aborter"> <span class="sig-name descname"><span class="pre">make_aborter</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.make_aborter" title="Link to this definition">¶</a></dt> <dd><p>Create the object to assign to <a class="reference internal" href="#flask.Flask.aborter" title="flask.Flask.aborter"><code class="xref py py-attr docutils literal notranslate"><span class="pre">aborter</span></code></a>. That object is called by <a class="reference internal" href="#flask.abort" title="flask.abort"><code class="xref py py-func docutils literal notranslate"><span class="pre">flask.abort()</span></code></a> to raise HTTP errors, and can be called directly as well.</p> <p>By default, this creates an instance of <a class="reference internal" href="#flask.Flask.aborter_class" title="flask.Flask.aborter_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">aborter_class</span></code></a>, which defaults to <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.Aborter" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.exceptions.Aborter</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.Aborter" title="(in Werkzeug v3.1.x)"><em>Aborter</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.make_config"> <span class="sig-name descname"><span class="pre">make_config</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">instance_relative</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.make_config" title="Link to this definition">¶</a></dt> <dd><p>Used to create the config attribute by the Flask constructor. The <code class="code docutils literal notranslate"><span class="pre">instance_relative</span></code> parameter is passed in from the constructor of Flask (there named <code class="code docutils literal notranslate"><span class="pre">instance_relative_config</span></code>) and indicates if the config should be relative to the instance path or the root path of the application.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>instance_relative</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Config" title="flask.config.Config"><em>Config</em></a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.name"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">name</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Flask.name" title="Link to this definition">¶</a></dt> <dd><p>The name of the application. This is usually the import name with the difference that it’s guessed from the run file if the import name is main. This name is used as a display name when Flask needs the name of the application. It can be set and overridden to change the value.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.patch"> <span class="sig-name descname"><span class="pre">patch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.patch" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;PATCH&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.permanent_session_lifetime"> <span class="sig-name descname"><span class="pre">permanent_session_lifetime</span></span><a class="headerlink" href="#flask.Flask.permanent_session_lifetime" title="Link to this definition">¶</a></dt> <dd><p>A <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">timedelta</span></code></a> which is used to set the expiration date of a permanent session. The default is 31 days which makes a permanent session survive for roughly one month.</p> <p>This attribute can also be configured from the config with the <code class="docutils literal notranslate"><span class="pre">PERMANENT_SESSION_LIFETIME</span></code> configuration key. Defaults to <code class="docutils literal notranslate"><span class="pre">timedelta(days=31)</span></code></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.post"> <span class="sig-name descname"><span class="pre">post</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.post" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;POST&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.put"> <span class="sig-name descname"><span class="pre">put</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.put" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;PUT&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.redirect"> <span class="sig-name descname"><span class="pre">redirect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">location</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">code</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">302</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.redirect" title="Link to this definition">¶</a></dt> <dd><p>Create a redirect response object.</p> <p>This is called by <a class="reference internal" href="#flask.redirect" title="flask.redirect"><code class="xref py py-func docutils literal notranslate"><span class="pre">flask.redirect()</span></code></a>, and can be called directly as well.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>location</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The URL to redirect to.</p></li> <li><p><strong>code</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – The status code for the redirect.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>BaseResponse</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2: </span>Moved from <code class="docutils literal notranslate"><span class="pre">flask.redirect</span></code>, which calls this method.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.register_blueprint"> <span class="sig-name descname"><span class="pre">register_blueprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">blueprint</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.register_blueprint" title="Link to this definition">¶</a></dt> <dd><p>Register a <a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Blueprint</span></code></a> on the application. Keyword arguments passed to this method will override the defaults set on the blueprint.</p> <p>Calls the blueprint’s <a class="reference internal" href="#flask.Blueprint.register" title="flask.Blueprint.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register()</span></code></a> method after recording the blueprint in the application’s <a class="reference internal" href="#flask.Flask.blueprints" title="flask.Flask.blueprints"><code class="xref py py-attr docutils literal notranslate"><span class="pre">blueprints</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>blueprint</strong> (<a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint"><em>Blueprint</em></a>) – The blueprint to register.</p></li> <li><p><strong>url_prefix</strong> – Blueprint routes will be prefixed with this.</p></li> <li><p><strong>subdomain</strong> – Blueprint routes will match on this subdomain.</p></li> <li><p><strong>url_defaults</strong> – Blueprint routes will use these default values for view arguments.</p></li> <li><p><strong>options</strong> (<em>t.Any</em>) – Additional keyword arguments are passed to <a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState"><code class="xref py py-class docutils literal notranslate"><span class="pre">BlueprintSetupState</span></code></a>. They can be accessed in <a class="reference internal" href="#flask.Blueprint.record" title="flask.Blueprint.record"><code class="xref py py-meth docutils literal notranslate"><span class="pre">record()</span></code></a> callbacks.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.1: </span>The <code class="docutils literal notranslate"><span class="pre">name</span></code> option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.register_error_handler"> <span class="sig-name descname"><span class="pre">register_error_handler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code_or_exception</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.register_error_handler" title="Link to this definition">¶</a></dt> <dd><p>Alternative error attach function to the <a class="reference internal" href="#flask.Flask.errorhandler" title="flask.Flask.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> decorator that is more straightforward to use for non decorator usage.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>code_or_exception</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>)</p></li> <li><p><strong>f</strong> (<em>ft.ErrorHandlerCallable</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.route"> <span class="sig-name descname"><span class="pre">route</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.route" title="Link to this definition">¶</a></dt> <dd><p>Decorate a view function to register it with the given URL rule and options. Calls <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a>, which has more details about the implementation.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="k">return</span> <span class="s2">&quot;Hello, World!&quot;</span> </pre></div> </div> <p>See <a class="reference internal" href="#url-route-registrations"><span class="std std-ref">URL Route Registrations</span></a>.</p> <p>The endpoint name for the route defaults to the name of the view function if the <code class="docutils literal notranslate"><span class="pre">endpoint</span></code> parameter isn’t passed.</p> <p>The <code class="docutils literal notranslate"><span class="pre">methods</span></code> parameter defaults to <code class="docutils literal notranslate"><span class="pre">[&quot;GET&quot;]</span></code>. <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> and <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> are added automatically.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The URL rule string.</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Extra options passed to the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Rule" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a> object.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.secret_key"> <span class="sig-name descname"><span class="pre">secret_key</span></span><a class="headerlink" href="#flask.Flask.secret_key" title="Link to this definition">¶</a></dt> <dd><p>If a secret key is set, cryptographic components can use this to sign cookies and other things. Set this to a complex random value when you want to use the secure cookie for instance.</p> <p>This attribute can also be configured from the config with the <a class="reference internal" href="../config/#SECRET_KEY" title="SECRET_KEY"><code class="xref py py-data docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a> configuration key. Defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.select_jinja_autoescape"> <span class="sig-name descname"><span class="pre">select_jinja_autoescape</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.select_jinja_autoescape" title="Link to this definition">¶</a></dt> <dd><p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if autoescaping should be active for the given template name. If no template name is given, returns <code class="code docutils literal notranslate"><span class="pre">True</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Autoescaping is now enabled by default for <code class="docutils literal notranslate"><span class="pre">.svg</span></code> files.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.shell_context_processor"> <span class="sig-name descname"><span class="pre">shell_context_processor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.shell_context_processor" title="Link to this definition">¶</a></dt> <dd><p>Registers a shell context processor function.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_shell_context_processor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_shell_context_processor</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.should_ignore_error"> <span class="sig-name descname"><span class="pre">should_ignore_error</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">error</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.should_ignore_error" title="Link to this definition">¶</a></dt> <dd><p>This is called to figure out if an error should be ignored or not as far as the teardown system is concerned. If this function returns <code class="docutils literal notranslate"><span class="pre">True</span></code> then the teardown handlers will not be passed the error.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>error</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.static_folder"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">static_folder</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Flask.static_folder" title="Link to this definition">¶</a></dt> <dd><p>The absolute path to the configured static folder. <code class="docutils literal notranslate"><span class="pre">None</span></code> if no static folder is set.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Flask.static_url_path"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">static_url_path</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Flask.static_url_path" title="Link to this definition">¶</a></dt> <dd><p>The URL prefix that the static route will be accessible from.</p> <p>If it was not configured during init, it is derived from <a class="reference internal" href="#flask.Flask.static_folder" title="flask.Flask.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.teardown_appcontext"> <span class="sig-name descname"><span class="pre">teardown_appcontext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.teardown_appcontext" title="Link to this definition">¶</a></dt> <dd><p>Registers a function to be called when the application context is popped. The application context is typically popped after the request context for each request, at the end of CLI commands, or after a manually pushed context ends.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">app_context</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <p>When the <code class="docutils literal notranslate"><span class="pre">with</span></code> block exits (or <code class="docutils literal notranslate"><span class="pre">ctx.pop()</span></code> is called), the teardown functions are called just before the app context is made inactive. Since a request context typically also manages an application context it would also be called when you pop a request context.</p> <p>When a teardown function was called because of an unhandled exception it will be passed an error object. If an <a class="reference internal" href="#flask.Flask.errorhandler" title="flask.Flask.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> is registered, it will handle the exception and the teardown will not receive it.</p> <p>Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a <code class="docutils literal notranslate"><span class="pre">try</span></code>/<code class="docutils literal notranslate"><span class="pre">except</span></code> block and log any errors.</p> <p>The return values of teardown functions are ignored.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_teardown</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_teardown</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.teardown_request"> <span class="sig-name descname"><span class="pre">teardown_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.teardown_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">test_request_context</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <p>When the <code class="docutils literal notranslate"><span class="pre">with</span></code> block exits (or <code class="docutils literal notranslate"><span class="pre">ctx.pop()</span></code> is called), the teardown functions are called just before the request context is made inactive.</p> <p>When a teardown function was called because of an unhandled exception it will be passed an error object. If an <a class="reference internal" href="#flask.Flask.errorhandler" title="flask.Flask.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> is registered, it will handle the exception and the teardown will not receive it.</p> <p>Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a <code class="docutils literal notranslate"><span class="pre">try</span></code>/<code class="docutils literal notranslate"><span class="pre">except</span></code> block and log any errors.</p> <p>The return values of teardown functions are ignored.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes after every request. When used on a blueprint, this executes after every request that the blueprint handles. To register with a blueprint and execute after every request, use <a class="reference internal" href="#flask.Blueprint.teardown_app_request" title="flask.Blueprint.teardown_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.teardown_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_teardown</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_teardown</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.template_filter"> <span class="sig-name descname"><span class="pre">template_filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.template_filter" title="Link to this definition">¶</a></dt> <dd><p>A decorator that is used to register custom template filter. You can specify a name for the filter, otherwise the function name will be used. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_filter</span><span class="p">()</span> <span class="k">def</span> <span class="nf">reverse</span><span class="p">(</span><span class="n">s</span><span class="p">):</span> <span class="k">return</span> <span class="n">s</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the filter, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_filter</em>], <em>T_template_filter</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.template_global"> <span class="sig-name descname"><span class="pre">template_global</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.template_global" title="Link to this definition">¶</a></dt> <dd><p>A decorator that is used to register a custom template global function. You can specify a name for the global function, otherwise the function name will be used. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_global</span><span class="p">()</span> <span class="k">def</span> <span class="nf">double</span><span class="p">(</span><span class="n">n</span><span class="p">):</span> <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">n</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the global function, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_global</em>], <em>T_template_global</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.template_test"> <span class="sig-name descname"><span class="pre">template_test</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.template_test" title="Link to this definition">¶</a></dt> <dd><p>A decorator that is used to register custom template test. You can specify a name for the test, otherwise the function name will be used. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">template_test</span><span class="p">()</span> <span class="k">def</span> <span class="nf">is_prime</span><span class="p">(</span><span class="n">n</span><span class="p">):</span> <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> <span class="k">return</span> <span class="kc">True</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">n</span><span class="p">)))</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span> <span class="k">if</span> <span class="n">n</span> <span class="o">%</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">return</span> <span class="kc">False</span> <span class="k">return</span> <span class="kc">True</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the test, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_test</em>], <em>T_template_test</em>]</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.test_cli_runner_class"> <span class="sig-name descname"><span class="pre">test_cli_runner_class</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><span class="pre">type</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#flask.testing.FlaskCliRunner" title="flask.testing.FlaskCliRunner"><span class="pre">FlaskCliRunner</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Flask.test_cli_runner_class" title="Link to this definition">¶</a></dt> <dd><p>The <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.testing.CliRunner" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">CliRunner</span></code></a> subclass, by default <a class="reference internal" href="#flask.testing.FlaskCliRunner" title="flask.testing.FlaskCliRunner"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskCliRunner</span></code></a> that is used by <a class="reference internal" href="#flask.Flask.test_cli_runner" title="flask.Flask.test_cli_runner"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_cli_runner()</span></code></a>. Its <code class="docutils literal notranslate"><span class="pre">__init__</span></code> method should take a Flask app object as the first argument.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 1.0.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.test_client_class"> <span class="sig-name descname"><span class="pre">test_client_class</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><span class="pre">type</span></a><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#flask.testing.FlaskClient" title="flask.testing.FlaskClient"><span class="pre">FlaskClient</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Flask.test_client_class" title="Link to this definition">¶</a></dt> <dd><p>The <a class="reference internal" href="#flask.Flask.test_client" title="flask.Flask.test_client"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_client()</span></code></a> method creates an instance of this test client class. Defaults to <a class="reference internal" href="#flask.testing.FlaskClient" title="flask.testing.FlaskClient"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskClient</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.testing"> <span class="sig-name descname"><span class="pre">testing</span></span><a class="headerlink" href="#flask.Flask.testing" title="Link to this definition">¶</a></dt> <dd><p>The testing flag. Set this to <code class="docutils literal notranslate"><span class="pre">True</span></code> to enable the test mode of Flask extensions (and in the future probably also Flask itself). For example this might activate test helpers that have an additional runtime cost which should not be enabled by default.</p> <p>If this is enabled and PROPAGATE_EXCEPTIONS is not changed from the default it’s implicitly enabled.</p> <p>This attribute can also be configured from the config with the <code class="docutils literal notranslate"><span class="pre">TESTING</span></code> configuration key. Defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.trap_http_exception"> <span class="sig-name descname"><span class="pre">trap_http_exception</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.trap_http_exception" title="Link to this definition">¶</a></dt> <dd><p>Checks if an HTTP exception should be trapped or not. By default this will return <code class="docutils literal notranslate"><span class="pre">False</span></code> for all exceptions except for a bad request key error if <code class="docutils literal notranslate"><span class="pre">TRAP_BAD_REQUEST_ERRORS</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>. It also returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if <code class="docutils literal notranslate"><span class="pre">TRAP_HTTP_EXCEPTIONS</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> <p>This is called for all HTTP exceptions raised by a view function. If it returns <code class="docutils literal notranslate"><span class="pre">True</span></code> for any exception the error handler for this exception is not called and it shows up as regular exception in the traceback. This is helpful for debugging implicitly raised HTTP exceptions.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>Bad request errors are not trapped by default in debug mode.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>e</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.url_defaults"> <span class="sig-name descname"><span class="pre">url_defaults</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.url_defaults" title="Link to this definition">¶</a></dt> <dd><p>Callback function for URL defaults for all view functions of the application. It’s called with the endpoint and values and should update the values passed in place.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every request. When used on a blueprint, this is called for requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_url_defaults" title="flask.Blueprint.app_url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_url_defaults()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_defaults</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_defaults</em></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_map_class"> <span class="sig-name descname"><span class="pre">url_map_class</span></span><a class="headerlink" href="#flask.Flask.url_map_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Map" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Map</span></code></a></p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_rule_class"> <span class="sig-name descname"><span class="pre">url_rule_class</span></span><a class="headerlink" href="#flask.Flask.url_rule_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Rule" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Flask.url_value_preprocessor"> <span class="sig-name descname"><span class="pre">url_value_preprocessor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Flask.url_value_preprocessor" title="Link to this definition">¶</a></dt> <dd><p>Register a URL value preprocessor function for all view functions in the application. These functions will be called before the <a class="reference internal" href="#flask.Flask.before_request" title="flask.Flask.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a> functions.</p> <p>The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in <code class="docutils literal notranslate"><span class="pre">g</span></code> rather than pass it to every view.</p> <p>The function is passed the endpoint name and values dict. The return value is ignored.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every request. When used on a blueprint, this is called for requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_url_value_preprocessor" title="flask.Blueprint.app_url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_url_value_preprocessor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_value_preprocessor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_value_preprocessor</em></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.instance_path"> <span class="sig-name descname"><span class="pre">instance_path</span></span><a class="headerlink" href="#flask.Flask.instance_path" title="Link to this definition">¶</a></dt> <dd><p>Holds the path to the instance folder.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.config"> <span class="sig-name descname"><span class="pre">config</span></span><a class="headerlink" href="#flask.Flask.config" title="Link to this definition">¶</a></dt> <dd><p>The configuration dictionary as <a class="reference internal" href="#flask.Config" title="flask.Config"><code class="xref py py-class docutils literal notranslate"><span class="pre">Config</span></code></a>. This behaves exactly like a regular dictionary but supports additional methods to load a config from files.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.aborter"> <span class="sig-name descname"><span class="pre">aborter</span></span><a class="headerlink" href="#flask.Flask.aborter" title="Link to this definition">¶</a></dt> <dd><p>An instance of <a class="reference internal" href="#flask.Flask.aborter_class" title="flask.Flask.aborter_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">aborter_class</span></code></a> created by <a class="reference internal" href="#flask.Flask.make_aborter" title="flask.Flask.make_aborter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_aborter()</span></code></a>. This is called by <a class="reference internal" href="#flask.abort" title="flask.abort"><code class="xref py py-func docutils literal notranslate"><span class="pre">flask.abort()</span></code></a> to raise HTTP errors, and can be called directly as well.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2: </span>Moved from <code class="docutils literal notranslate"><span class="pre">flask.abort</span></code>, which calls this object.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.json"> <span class="sig-name descname"><span class="pre">json</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference internal" href="#flask.json.provider.JSONProvider" title="flask.json.provider.JSONProvider"><span class="pre">JSONProvider</span></a></em><a class="headerlink" href="#flask.Flask.json" title="Link to this definition">¶</a></dt> <dd><p>Provides access to JSON methods. Functions in <code class="docutils literal notranslate"><span class="pre">flask.json</span></code> will call methods on this provider when the application context is active. Used for handling JSON requests and responses.</p> <p>An instance of <a class="reference internal" href="#flask.Flask.json_provider_class" title="flask.Flask.json_provider_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">json_provider_class</span></code></a>. Can be customized by changing that attribute on a subclass, or by assigning to this attribute afterwards.</p> <p>The default, <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider" title="flask.json.provider.DefaultJSONProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">DefaultJSONProvider</span></code></a>, uses Python’s built-in <a class="reference external" href="https://docs.python.org/3/library/json.html#module-json" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> library. A different provider can use a different JSON library.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_build_error_handlers"> <span class="sig-name descname"><span class="pre">url_build_error_handlers</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">t.Callable</span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><span class="pre">Exception</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.url_build_error_handlers" title="Link to this definition">¶</a></dt> <dd><p>A list of functions that are called by <a class="reference internal" href="#flask.Flask.handle_url_build_error" title="flask.Flask.handle_url_build_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_url_build_error()</span></code></a> when <a class="reference internal" href="#flask.Flask.url_for" title="flask.Flask.url_for"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_for()</span></code></a> raises a <code class="xref py py-exc docutils literal notranslate"><span class="pre">BuildError</span></code>. Each function is called with <code class="docutils literal notranslate"><span class="pre">error</span></code>, <code class="docutils literal notranslate"><span class="pre">endpoint</span></code> and <code class="docutils literal notranslate"><span class="pre">values</span></code>. If a function returns <code class="docutils literal notranslate"><span class="pre">None</span></code> or raises a <code class="docutils literal notranslate"><span class="pre">BuildError</span></code>, it is skipped. Otherwise, its return value is returned by <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.teardown_appcontext_funcs"> <span class="sig-name descname"><span class="pre">teardown_appcontext_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.TeardownCallable</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.teardown_appcontext_funcs" title="Link to this definition">¶</a></dt> <dd><p>A list of functions that are called when the application context is destroyed. Since the application context is also torn down if the request ends this is the place to store code that disconnects from databases.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.shell_context_processors"> <span class="sig-name descname"><span class="pre">shell_context_processors</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.ShellContextProcessorCallable</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.shell_context_processors" title="Link to this definition">¶</a></dt> <dd><p>A list of shell context processor functions that should be run when a shell context is created.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.blueprints"> <span class="sig-name descname"><span class="pre">blueprints</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint"><span class="pre">Blueprint</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.blueprints" title="Link to this definition">¶</a></dt> <dd><p>Maps registered blueprint names to blueprint objects. The dict retains the order the blueprints were registered in. Blueprints can be registered multiple times, this dict does not track how often they were attached.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.extensions"> <span class="sig-name descname"><span class="pre">extensions</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.extensions" title="Link to this definition">¶</a></dt> <dd><p>a place where extensions can store application specific state. For example this is where an extension could store database engines and similar things.</p> <p>The key must match the name of the extension module. For example in case of a “Flask-Foo” extension in <code class="code docutils literal notranslate"><span class="pre">flask_foo</span></code>, the key would be <code class="docutils literal notranslate"><span class="pre">'foo'</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_map"> <span class="sig-name descname"><span class="pre">url_map</span></span><a class="headerlink" href="#flask.Flask.url_map" title="Link to this definition">¶</a></dt> <dd><p>The <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Map" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Map</span></code></a> for this instance. You can use this to change the routing converters after the class was created but before any routes are connected. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">werkzeug.routing</span> <span class="kn">import</span> <span class="n">BaseConverter</span> <span class="k">class</span> <span class="nc">ListConverter</span><span class="p">(</span><span class="n">BaseConverter</span><span class="p">):</span> <span class="k">def</span> <span class="nf">to_python</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="k">return</span> <span class="n">value</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;,&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">to_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span> <span class="k">return</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">super</span><span class="p">(</span><span class="n">ListConverter</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">to_url</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">values</span><span class="p">)</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> <span class="n">app</span><span class="o">.</span><span class="n">url_map</span><span class="o">.</span><span class="n">converters</span><span class="p">[</span><span class="s1">&#39;list&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ListConverter</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.import_name"> <span class="sig-name descname"><span class="pre">import_name</span></span><a class="headerlink" href="#flask.Flask.import_name" title="Link to this definition">¶</a></dt> <dd><p>The name of the package or module that this object belongs to. Do not change this once it is set by the constructor.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.template_folder"> <span class="sig-name descname"><span class="pre">template_folder</span></span><a class="headerlink" href="#flask.Flask.template_folder" title="Link to this definition">¶</a></dt> <dd><p>The path to the templates folder, relative to <a class="reference internal" href="#flask.Flask.root_path" title="flask.Flask.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>, to add to the template loader. <code class="docutils literal notranslate"><span class="pre">None</span></code> if templates should not be added.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.root_path"> <span class="sig-name descname"><span class="pre">root_path</span></span><a class="headerlink" href="#flask.Flask.root_path" title="Link to this definition">¶</a></dt> <dd><p>Absolute path to the package on the filesystem. Used to look up resources contained in the package.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.view_functions"> <span class="sig-name descname"><span class="pre">view_functions</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ft.RouteCallable</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.view_functions" title="Link to this definition">¶</a></dt> <dd><p>A dictionary mapping endpoint names to view functions.</p> <p>To register a view function, use the <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.error_handler_spec"> <span class="sig-name descname"><span class="pre">error_handler_spec</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><span class="pre">type</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><span class="pre">Exception</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ft.ErrorHandlerCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.error_handler_spec" title="Link to this definition">¶</a></dt> <dd><p>A data structure of registered error handlers, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">{code:</span> <span class="pre">{class:</span> <span class="pre">handler}}}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the handlers are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests. The <code class="docutils literal notranslate"><span class="pre">code</span></code> key is the HTTP status code for <code class="docutils literal notranslate"><span class="pre">HTTPException</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for other exceptions. The innermost dictionary maps exception classes to handler functions.</p> <p>To register an error handler, use the <a class="reference internal" href="#flask.Flask.errorhandler" title="flask.Flask.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.before_request_funcs"> <span class="sig-name descname"><span class="pre">before_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.BeforeRequestCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.before_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the beginning of each request, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.before_request" title="flask.Flask.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.after_request_funcs"> <span class="sig-name descname"><span class="pre">after_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AfterRequestCallable</span><span class="p"><span class="pre">[</span></span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.after_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the end of each request, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.after_request" title="flask.Flask.after_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">after_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.teardown_request_funcs"> <span class="sig-name descname"><span class="pre">teardown_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.TeardownCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.teardown_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the end of each request even if an exception is raised, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.template_context_processors"> <span class="sig-name descname"><span class="pre">template_context_processors</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.TemplateContextProcessorCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.template_context_processors" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to pass extra context values when rendering templates, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.context_processor" title="flask.Flask.context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">context_processor()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_value_preprocessors"> <span class="sig-name descname"><span class="pre">url_value_preprocessors</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.URLValuePreprocessorCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.url_value_preprocessors" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to modify the keyword arguments passed to the view function, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.url_value_preprocessor" title="flask.Flask.url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_value_preprocessor()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Flask.url_default_functions"> <span class="sig-name descname"><span class="pre">url_default_functions</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.URLDefaultCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Flask.url_default_functions" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to modify the keyword arguments when generating URLs, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Flask.url_defaults" title="flask.Flask.url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_defaults()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> </dd></dl> </section> <section id="blueprint-objects"> <h2>Blueprint Objects<a class="headerlink" href="#blueprint-objects" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.Blueprint"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">Blueprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">import_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">static_folder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">static_url_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">template_folder</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">url_prefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subdomain</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">url_defaults</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">root_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cli_group</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint" title="Link to this definition">¶</a></dt> <dd><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>import_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>static_folder</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>static_url_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>template_folder</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>url_prefix</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>subdomain</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>url_defaults</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>root_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>cli_group</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.cli"> <span class="sig-name descname"><span class="pre">cli</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Group</span></em><a class="headerlink" href="#flask.Blueprint.cli" title="Link to this definition">¶</a></dt> <dd><p>The Click command group for registering CLI commands for this object. The commands are available from the <code class="docutils literal notranslate"><span class="pre">flask</span></code> command once the application has been discovered and blueprints have been registered.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.get_send_file_max_age"> <span class="sig-name descname"><span class="pre">get_send_file_max_age</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.get_send_file_max_age" title="Link to this definition">¶</a></dt> <dd><p>Used by <a class="reference internal" href="#flask.send_file" title="flask.send_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_file()</span></code></a> to determine the <code class="docutils literal notranslate"><span class="pre">max_age</span></code> cache value for a given file path if it wasn’t passed.</p> <p>By default, this returns <a class="reference internal" href="../config/#SEND_FILE_MAX_AGE_DEFAULT" title="SEND_FILE_MAX_AGE_DEFAULT"><code class="xref py py-data docutils literal notranslate"><span class="pre">SEND_FILE_MAX_AGE_DEFAULT</span></code></a> from the configuration of <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a>. This defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>, which tells the browser to use conditional requests instead of a timed cache, which is usually preferable.</p> <p>Note this is a duplicate of the same method in the Flask class.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The default configuration is <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of 12 hours.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)">int</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.send_static_file"> <span class="sig-name descname"><span class="pre">send_static_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.send_static_file" title="Link to this definition">¶</a></dt> <dd><p>The view function used to serve files from <a class="reference internal" href="#flask.Blueprint.static_folder" title="flask.Blueprint.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a>. A route is automatically registered for this view at <a class="reference internal" href="#flask.Blueprint.static_url_path" title="flask.Blueprint.static_url_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_url_path</span></code></a> if <a class="reference internal" href="#flask.Blueprint.static_folder" title="flask.Blueprint.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a> is set.</p> <p>Note this is a duplicate of the same method in the Flask class.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.open_resource"> <span class="sig-name descname"><span class="pre">open_resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">resource</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rb'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'utf-8'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.open_resource" title="Link to this definition">¶</a></dt> <dd><p>Open a resource file relative to <a class="reference internal" href="#flask.Blueprint.root_path" title="flask.Blueprint.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a> for reading. The blueprint-relative equivalent of the app’s <a class="reference internal" href="#flask.Flask.open_resource" title="flask.Flask.open_resource"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_resource()</span></code></a> method.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>resource</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Path to the resource relative to <a class="reference internal" href="#flask.Blueprint.root_path" title="flask.Blueprint.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>.</p></li> <li><p><strong>mode</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Open the file in this mode. Only reading is supported, valid values are <code class="docutils literal notranslate"><span class="pre">&quot;r&quot;</span></code> (or <code class="docutils literal notranslate"><span class="pre">&quot;rt&quot;</span></code>) and <code class="docutils literal notranslate"><span class="pre">&quot;rb&quot;</span></code>.</p></li> <li><p><strong>encoding</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – Open the file with this encoding when opening in text mode. This is ignored when opening in binary mode.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a></p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <code class="docutils literal notranslate"><span class="pre">encoding</span></code> parameter.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.add_app_template_filter"> <span class="sig-name descname"><span class="pre">add_app_template_filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.add_app_template_filter" title="Link to this definition">¶</a></dt> <dd><p>Register a template filter, available in any template rendered by the application. Works like the <a class="reference internal" href="#flask.Blueprint.app_template_filter" title="flask.Blueprint.app_template_filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app_template_filter()</span></code></a> decorator. Equivalent to <a class="reference internal" href="#flask.Flask.add_template_filter" title="flask.Flask.add_template_filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.add_template_filter()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the filter, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.add_app_template_global"> <span class="sig-name descname"><span class="pre">add_app_template_global</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.add_app_template_global" title="Link to this definition">¶</a></dt> <dd><p>Register a template global, available in any template rendered by the application. Works like the <a class="reference internal" href="#flask.Blueprint.app_template_global" title="flask.Blueprint.app_template_global"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app_template_global()</span></code></a> decorator. Equivalent to <a class="reference internal" href="#flask.Flask.add_template_global" title="flask.Flask.add_template_global"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.add_template_global()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the global, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.add_app_template_test"> <span class="sig-name descname"><span class="pre">add_app_template_test</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.add_app_template_test" title="Link to this definition">¶</a></dt> <dd><p>Register a template test, available in any template rendered by the application. Works like the <a class="reference internal" href="#flask.Blueprint.app_template_test" title="flask.Blueprint.app_template_test"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app_template_test()</span></code></a> decorator. Equivalent to <a class="reference internal" href="#flask.Flask.add_template_test" title="flask.Flask.add_template_test"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.add_template_test()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the test, otherwise the function name will be used.</p></li> <li><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>...</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.add_url_rule"> <span class="sig-name descname"><span class="pre">add_url_rule</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">endpoint</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">view_func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">provide_automatic_options</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.add_url_rule" title="Link to this definition">¶</a></dt> <dd><p>Register a URL rule with the blueprint. See <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.add_url_rule()</span></code></a> for full documentation.</p> <p>The URL rule is prefixed with the blueprint’s URL prefix. The endpoint name, used with <a class="reference internal" href="#flask.url_for" title="flask.url_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">url_for()</span></code></a>, is prefixed with the blueprint’s name.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>view_func</strong> (<em>ft.RouteCallable</em><em> | </em><em>None</em>)</p></li> <li><p><strong>provide_automatic_options</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>options</strong> (<em>t.Any</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.after_app_request"> <span class="sig-name descname"><span class="pre">after_app_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.after_app_request" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.after_request" title="flask.Blueprint.after_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">after_request()</span></code></a>, but after every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.after_request" title="flask.Flask.after_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.after_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_after_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_after_request</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.after_request"> <span class="sig-name descname"><span class="pre">after_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.after_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to run after each request to this object.</p> <p>The function is called with the response object, and must return a response object. This allows the functions to modify or replace the response before it is sent.</p> <p>If a function raises an exception, any remaining <code class="docutils literal notranslate"><span class="pre">after_request</span></code> functions will not be called. Therefore, this should not be used for actions that must execute, such as to close resources. Use <a class="reference internal" href="#flask.Blueprint.teardown_request" title="flask.Blueprint.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a> for that.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes after every request. When used on a blueprint, this executes after every request that the blueprint handles. To register with a blueprint and execute after every request, use <a class="reference internal" href="#flask.Blueprint.after_app_request" title="flask.Blueprint.after_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.after_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_after_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_after_request</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_context_processor"> <span class="sig-name descname"><span class="pre">app_context_processor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_context_processor" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.context_processor" title="flask.Blueprint.context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">context_processor()</span></code></a>, but for templates rendered by every view, not only by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.context_processor" title="flask.Flask.context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.context_processor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_template_context_processor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_template_context_processor</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_errorhandler"> <span class="sig-name descname"><span class="pre">app_errorhandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_errorhandler" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.errorhandler" title="flask.Blueprint.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a>, but for every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.errorhandler" title="flask.Flask.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.errorhandler()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>code</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_error_handler</em>], <em>T_error_handler</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_template_filter"> <span class="sig-name descname"><span class="pre">app_template_filter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_template_filter" title="Link to this definition">¶</a></dt> <dd><p>Register a template filter, available in any template rendered by the application. Equivalent to <a class="reference internal" href="#flask.Flask.template_filter" title="flask.Flask.template_filter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.template_filter()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the filter, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_filter</em>], <em>T_template_filter</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_template_global"> <span class="sig-name descname"><span class="pre">app_template_global</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_template_global" title="Link to this definition">¶</a></dt> <dd><p>Register a template global, available in any template rendered by the application. Equivalent to <a class="reference internal" href="#flask.Flask.template_global" title="flask.Flask.template_global"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.template_global()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the global, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_global</em>], <em>T_template_global</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_template_test"> <span class="sig-name descname"><span class="pre">app_template_test</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_template_test" title="Link to this definition">¶</a></dt> <dd><p>Register a template test, available in any template rendered by the application. Equivalent to <a class="reference internal" href="#flask.Flask.template_test" title="flask.Flask.template_test"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.template_test()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the optional name of the test, otherwise the function name will be used.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_template_test</em>], <em>T_template_test</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_url_defaults"> <span class="sig-name descname"><span class="pre">app_url_defaults</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_url_defaults" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.url_defaults" title="flask.Blueprint.url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_defaults()</span></code></a>, but for every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.url_defaults" title="flask.Flask.url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.url_defaults()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_defaults</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_defaults</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.app_url_value_preprocessor"> <span class="sig-name descname"><span class="pre">app_url_value_preprocessor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.app_url_value_preprocessor" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.url_value_preprocessor" title="flask.Blueprint.url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_value_preprocessor()</span></code></a>, but for every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.url_value_preprocessor" title="flask.Flask.url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.url_value_preprocessor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_value_preprocessor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_value_preprocessor</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.before_app_request"> <span class="sig-name descname"><span class="pre">before_app_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.before_app_request" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.before_request" title="flask.Blueprint.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a>, but before every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.before_request" title="flask.Flask.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.before_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_before_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_before_request</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.before_request"> <span class="sig-name descname"><span class="pre">before_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.before_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to run before each request.</p> <p>For example, this can be used to open a database connection, or to load the logged in user from the session.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">before_request</span> <span class="k">def</span> <span class="nf">load_user</span><span class="p">():</span> <span class="k">if</span> <span class="s2">&quot;user_id&quot;</span> <span class="ow">in</span> <span class="n">session</span><span class="p">:</span> <span class="n">g</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">session</span><span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">])</span> </pre></div> </div> <p>The function will be called without any arguments. If it returns a non-<code class="docutils literal notranslate"><span class="pre">None</span></code> value, the value is handled as if it was the return value from the view, and further request handling is stopped.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes before every request. When used on a blueprint, this executes before every request that the blueprint handles. To register with a blueprint and execute before every request, use <a class="reference internal" href="#flask.Blueprint.before_app_request" title="flask.Blueprint.before_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.before_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_before_request</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_before_request</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.context_processor"> <span class="sig-name descname"><span class="pre">context_processor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.context_processor" title="Link to this definition">¶</a></dt> <dd><p>Registers a template context processor function. These functions run before rendering a template. The keys of the returned dict are added as variables available in the template.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every rendered template. When used on a blueprint, this is called for templates rendered from the blueprint’s views. To register with a blueprint and affect every template, use <a class="reference internal" href="#flask.Blueprint.app_context_processor" title="flask.Blueprint.app_context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_context_processor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_template_context_processor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_template_context_processor</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.delete"> <span class="sig-name descname"><span class="pre">delete</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.delete" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;DELETE&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.endpoint"> <span class="sig-name descname"><span class="pre">endpoint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.endpoint" title="Link to this definition">¶</a></dt> <dd><p>Decorate a view function to register it for the given endpoint. Used if a rule is added without a <code class="docutils literal notranslate"><span class="pre">view_func</span></code> with <a class="reference internal" href="#flask.Blueprint.add_url_rule" title="flask.Blueprint.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a>.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s2">&quot;/ex&quot;</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="s2">&quot;example&quot;</span><span class="p">)</span> <span class="nd">@app</span><span class="o">.</span><span class="n">endpoint</span><span class="p">(</span><span class="s2">&quot;example&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">example</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The endpoint name to associate with the view function.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>F</em>], <em>F</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.errorhandler"> <span class="sig-name descname"><span class="pre">errorhandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code_or_exception</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.errorhandler" title="Link to this definition">¶</a></dt> <dd><p>Register a function to handle errors by code or exception class.</p> <p>A decorator that is used to register a function given an error code. Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="mi">404</span><span class="p">)</span> <span class="k">def</span> <span class="nf">page_not_found</span><span class="p">(</span><span class="n">error</span><span class="p">):</span> <span class="k">return</span> <span class="s1">&#39;This page does not exist&#39;</span><span class="p">,</span> <span class="mi">404</span> </pre></div> </div> <p>You can also register handlers for arbitrary exceptions:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="n">DatabaseError</span><span class="p">)</span> <span class="k">def</span> <span class="nf">special_exception_handler</span><span class="p">(</span><span class="n">error</span><span class="p">):</span> <span class="k">return</span> <span class="s1">&#39;Database connection failed&#39;</span><span class="p">,</span> <span class="mi">500</span> </pre></div> </div> <p>This is available on both app and blueprint objects. When used on an app, this can handle errors from every request. When used on a blueprint, this can handle errors from requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_errorhandler" title="flask.Blueprint.app_errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_errorhandler()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>Use <a class="reference internal" href="#flask.Blueprint.register_error_handler" title="flask.Blueprint.register_error_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_error_handler()</span></code></a> instead of modifying <a class="reference internal" href="#flask.Blueprint.error_handler_spec" title="flask.Blueprint.error_handler_spec"><code class="xref py py-attr docutils literal notranslate"><span class="pre">error_handler_spec</span></code></a> directly, for application wide error handlers.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span>One can now additionally also register custom exception types that do not necessarily have to be a subclass of the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.HTTPException" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPException</span></code></a> class.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>code_or_exception</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – the code as integer for the handler, or an arbitrary exception</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_error_handler</em>], <em>T_error_handler</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.get"> <span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.get" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;GET&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Blueprint.has_static_folder"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">has_static_folder</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Blueprint.has_static_folder" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if <a class="reference internal" href="#flask.Blueprint.static_folder" title="flask.Blueprint.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a> is set.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Blueprint.jinja_loader"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">jinja_loader</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.BaseLoader" title="(in Jinja v3.1.x)"><span class="pre">BaseLoader</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Blueprint.jinja_loader" title="Link to this definition">¶</a></dt> <dd><p>The Jinja loader for this object’s templates. By default this is a class <a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.FileSystemLoader" title="(in Jinja v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">jinja2.loaders.FileSystemLoader</span></code></a> to <a class="reference internal" href="#flask.Blueprint.template_folder" title="flask.Blueprint.template_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">template_folder</span></code></a> if it is set.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.make_setup_state"> <span class="sig-name descname"><span class="pre">make_setup_state</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">first_registration</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.make_setup_state" title="Link to this definition">¶</a></dt> <dd><p>Creates an instance of <a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BlueprintSetupState()</span></code></a> object that is later passed to the register callback functions. Subclasses can override this to return a subclass of the setup state.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<em>App</em>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>]</em>)</p></li> <li><p><strong>first_registration</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState">BlueprintSetupState</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.patch"> <span class="sig-name descname"><span class="pre">patch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.patch" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;PATCH&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.post"> <span class="sig-name descname"><span class="pre">post</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.post" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;POST&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.put"> <span class="sig-name descname"><span class="pre">put</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.put" title="Link to this definition">¶</a></dt> <dd><p>Shortcut for <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> with <code class="docutils literal notranslate"><span class="pre">methods=[&quot;PUT&quot;]</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.record"> <span class="sig-name descname"><span class="pre">record</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.record" title="Link to this definition">¶</a></dt> <dd><p>Registers a function that is called when the blueprint is registered on the application. This function is called with the state as argument as returned by the <a class="reference internal" href="#flask.Blueprint.make_setup_state" title="flask.Blueprint.make_setup_state"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_setup_state()</span></code></a> method.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>func</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.sansio.blueprints.BlueprintSetupState"><em>BlueprintSetupState</em></a><em>]</em><em>, </em><em>None</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.record_once"> <span class="sig-name descname"><span class="pre">record_once</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.record_once" title="Link to this definition">¶</a></dt> <dd><p>Works like <a class="reference internal" href="#flask.Blueprint.record" title="flask.Blueprint.record"><code class="xref py py-meth docutils literal notranslate"><span class="pre">record()</span></code></a> but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>func</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.sansio.blueprints.BlueprintSetupState"><em>BlueprintSetupState</em></a><em>]</em><em>, </em><em>None</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.register"> <span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.register" title="Link to this definition">¶</a></dt> <dd><p>Called by <a class="reference internal" href="#flask.Flask.register_blueprint" title="flask.Flask.register_blueprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.register_blueprint()</span></code></a> to register all views and callbacks registered on the blueprint with the application. Creates a <a class="reference internal" href="#flask.blueprints.BlueprintSetupState" title="flask.blueprints.BlueprintSetupState"><code class="xref py py-class docutils literal notranslate"><span class="pre">BlueprintSetupState</span></code></a> and calls each <a class="reference internal" href="#flask.Blueprint.record" title="flask.Blueprint.record"><code class="xref py py-meth docutils literal notranslate"><span class="pre">record()</span></code></a> callback with it.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<em>App</em>) – The application this blueprint is being registered with.</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>]</em>) – Keyword arguments forwarded from <a class="reference internal" href="#flask.Flask.register_blueprint" title="flask.Flask.register_blueprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_blueprint()</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Nested blueprints now correctly apply subdomains.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>Registering the same blueprint with the same name multiple times is an error.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.1: </span>Nested blueprints are registered with their dotted name. This allows different blueprints with the same name to be nested at different locations.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.1: </span>The <code class="docutils literal notranslate"><span class="pre">name</span></code> option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.register_blueprint"> <span class="sig-name descname"><span class="pre">register_blueprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">blueprint</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.register_blueprint" title="Link to this definition">¶</a></dt> <dd><p>Register a <a class="reference internal" href="#flask.Blueprint" title="flask.Blueprint"><code class="xref py py-class docutils literal notranslate"><span class="pre">Blueprint</span></code></a> on this blueprint. Keyword arguments passed to this method will override the defaults set on the blueprint.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.1: </span>The <code class="docutils literal notranslate"><span class="pre">name</span></code> option can be used to change the (pre-dotted) name the blueprint is registered with. This allows the same blueprint to be registered multiple times with unique names for <code class="docutils literal notranslate"><span class="pre">url_for</span></code>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>blueprint</strong> (<em>Blueprint</em>)</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.register_error_handler"> <span class="sig-name descname"><span class="pre">register_error_handler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code_or_exception</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.register_error_handler" title="Link to this definition">¶</a></dt> <dd><p>Alternative error attach function to the <a class="reference internal" href="#flask.Blueprint.errorhandler" title="flask.Blueprint.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> decorator that is more straightforward to use for non decorator usage.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>code_or_exception</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><em>Exception</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>)</p></li> <li><p><strong>f</strong> (<em>ft.ErrorHandlerCallable</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.route"> <span class="sig-name descname"><span class="pre">route</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.route" title="Link to this definition">¶</a></dt> <dd><p>Decorate a view function to register it with the given URL rule and options. Calls <a class="reference internal" href="#flask.Blueprint.add_url_rule" title="flask.Blueprint.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a>, which has more details about the implementation.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="k">return</span> <span class="s2">&quot;Hello, World!&quot;</span> </pre></div> </div> <p>See <a class="reference internal" href="#url-route-registrations"><span class="std std-ref">URL Route Registrations</span></a>.</p> <p>The endpoint name for the route defaults to the name of the view function if the <code class="docutils literal notranslate"><span class="pre">endpoint</span></code> parameter isn’t passed.</p> <p>The <code class="docutils literal notranslate"><span class="pre">methods</span></code> parameter defaults to <code class="docutils literal notranslate"><span class="pre">[&quot;GET&quot;]</span></code>. <code class="docutils literal notranslate"><span class="pre">HEAD</span></code> and <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> are added automatically.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The URL rule string.</p></li> <li><p><strong>options</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Extra options passed to the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Rule" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a> object.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<em>T_route</em>], <em>T_route</em>]</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Blueprint.static_folder"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">static_folder</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Blueprint.static_folder" title="Link to this definition">¶</a></dt> <dd><p>The absolute path to the configured static folder. <code class="docutils literal notranslate"><span class="pre">None</span></code> if no static folder is set.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Blueprint.static_url_path"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">static_url_path</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Blueprint.static_url_path" title="Link to this definition">¶</a></dt> <dd><p>The URL prefix that the static route will be accessible from.</p> <p>If it was not configured during init, it is derived from <a class="reference internal" href="#flask.Blueprint.static_folder" title="flask.Blueprint.static_folder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">static_folder</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.teardown_app_request"> <span class="sig-name descname"><span class="pre">teardown_app_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.teardown_app_request" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Blueprint.teardown_request" title="flask.Blueprint.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a>, but after every request, not only those handled by the blueprint. Equivalent to <a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.teardown_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_teardown</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_teardown</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.teardown_request"> <span class="sig-name descname"><span class="pre">teardown_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.teardown_request" title="Link to this definition">¶</a></dt> <dd><p>Register a function to be called when the request context is popped. Typically this happens at the end of each request, but contexts may be pushed manually as well during testing.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">app</span><span class="o">.</span><span class="n">test_request_context</span><span class="p">():</span> <span class="o">...</span> </pre></div> </div> <p>When the <code class="docutils literal notranslate"><span class="pre">with</span></code> block exits (or <code class="docutils literal notranslate"><span class="pre">ctx.pop()</span></code> is called), the teardown functions are called just before the request context is made inactive.</p> <p>When a teardown function was called because of an unhandled exception it will be passed an error object. If an <a class="reference internal" href="#flask.Blueprint.errorhandler" title="flask.Blueprint.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> is registered, it will handle the exception and the teardown will not receive it.</p> <p>Teardown functions must avoid raising exceptions. If they execute code that might fail they must surround that code with a <code class="docutils literal notranslate"><span class="pre">try</span></code>/<code class="docutils literal notranslate"><span class="pre">except</span></code> block and log any errors.</p> <p>The return values of teardown functions are ignored.</p> <p>This is available on both app and blueprint objects. When used on an app, this executes after every request. When used on a blueprint, this executes after every request that the blueprint handles. To register with a blueprint and execute after every request, use <a class="reference internal" href="#flask.Blueprint.teardown_app_request" title="flask.Blueprint.teardown_app_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.teardown_app_request()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_teardown</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_teardown</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.url_defaults"> <span class="sig-name descname"><span class="pre">url_defaults</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.url_defaults" title="Link to this definition">¶</a></dt> <dd><p>Callback function for URL defaults for all view functions of the application. It’s called with the endpoint and values and should update the values passed in place.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every request. When used on a blueprint, this is called for requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_url_defaults" title="flask.Blueprint.app_url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_url_defaults()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_defaults</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_defaults</em></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Blueprint.url_value_preprocessor"> <span class="sig-name descname"><span class="pre">url_value_preprocessor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Blueprint.url_value_preprocessor" title="Link to this definition">¶</a></dt> <dd><p>Register a URL value preprocessor function for all view functions in the application. These functions will be called before the <a class="reference internal" href="#flask.Blueprint.before_request" title="flask.Blueprint.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a> functions.</p> <p>The function can modify the values captured from the matched url before they are passed to the view. For example, this can be used to pop a common language code value and place it in <code class="docutils literal notranslate"><span class="pre">g</span></code> rather than pass it to every view.</p> <p>The function is passed the endpoint name and values dict. The return value is ignored.</p> <p>This is available on both app and blueprint objects. When used on an app, this is called for every request. When used on a blueprint, this is called for requests that the blueprint handles. To register with a blueprint and affect every request, use <a class="reference internal" href="#flask.Blueprint.app_url_value_preprocessor" title="flask.Blueprint.app_url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Blueprint.app_url_value_preprocessor()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>T_url_value_preprocessor</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>T_url_value_preprocessor</em></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.import_name"> <span class="sig-name descname"><span class="pre">import_name</span></span><a class="headerlink" href="#flask.Blueprint.import_name" title="Link to this definition">¶</a></dt> <dd><p>The name of the package or module that this object belongs to. Do not change this once it is set by the constructor.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.template_folder"> <span class="sig-name descname"><span class="pre">template_folder</span></span><a class="headerlink" href="#flask.Blueprint.template_folder" title="Link to this definition">¶</a></dt> <dd><p>The path to the templates folder, relative to <a class="reference internal" href="#flask.Blueprint.root_path" title="flask.Blueprint.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>, to add to the template loader. <code class="docutils literal notranslate"><span class="pre">None</span></code> if templates should not be added.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.root_path"> <span class="sig-name descname"><span class="pre">root_path</span></span><a class="headerlink" href="#flask.Blueprint.root_path" title="Link to this definition">¶</a></dt> <dd><p>Absolute path to the package on the filesystem. Used to look up resources contained in the package.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.view_functions"> <span class="sig-name descname"><span class="pre">view_functions</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ft.RouteCallable</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.view_functions" title="Link to this definition">¶</a></dt> <dd><p>A dictionary mapping endpoint names to view functions.</p> <p>To register a view function, use the <a class="reference internal" href="#flask.Blueprint.route" title="flask.Blueprint.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.error_handler_spec"> <span class="sig-name descname"><span class="pre">error_handler_spec</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><span class="pre">type</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#Exception" title="(in Python v3.13)"><span class="pre">Exception</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">ft.ErrorHandlerCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.error_handler_spec" title="Link to this definition">¶</a></dt> <dd><p>A data structure of registered error handlers, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">{code:</span> <span class="pre">{class:</span> <span class="pre">handler}}}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the handlers are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests. The <code class="docutils literal notranslate"><span class="pre">code</span></code> key is the HTTP status code for <code class="docutils literal notranslate"><span class="pre">HTTPException</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for other exceptions. The innermost dictionary maps exception classes to handler functions.</p> <p>To register an error handler, use the <a class="reference internal" href="#flask.Blueprint.errorhandler" title="flask.Blueprint.errorhandler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">errorhandler()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.before_request_funcs"> <span class="sig-name descname"><span class="pre">before_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.BeforeRequestCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.before_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the beginning of each request, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.before_request" title="flask.Blueprint.before_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">before_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.after_request_funcs"> <span class="sig-name descname"><span class="pre">after_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AfterRequestCallable</span><span class="p"><span class="pre">[</span></span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.after_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the end of each request, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.after_request" title="flask.Blueprint.after_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">after_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.teardown_request_funcs"> <span class="sig-name descname"><span class="pre">teardown_request_funcs</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.TeardownCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.teardown_request_funcs" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call at the end of each request even if an exception is raised, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.teardown_request" title="flask.Blueprint.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.template_context_processors"> <span class="sig-name descname"><span class="pre">template_context_processors</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.TemplateContextProcessorCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.template_context_processors" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to pass extra context values when rendering templates, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.context_processor" title="flask.Blueprint.context_processor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">context_processor()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.url_value_preprocessors"> <span class="sig-name descname"><span class="pre">url_value_preprocessors</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.URLValuePreprocessorCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.url_value_preprocessors" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to modify the keyword arguments passed to the view function, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.url_value_preprocessor" title="flask.Blueprint.url_value_preprocessor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_value_preprocessor()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Blueprint.url_default_functions"> <span class="sig-name descname"><span class="pre">url_default_functions</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.AppOrBlueprintKey</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><span class="pre">ft.URLDefaultCallable</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Blueprint.url_default_functions" title="Link to this definition">¶</a></dt> <dd><p>A data structure of functions to call to modify the keyword arguments when generating URLs, in the format <code class="docutils literal notranslate"><span class="pre">{scope:</span> <span class="pre">[functions]}</span></code>. The <code class="docutils literal notranslate"><span class="pre">scope</span></code> key is the name of a blueprint the functions are active for, or <code class="docutils literal notranslate"><span class="pre">None</span></code> for all requests.</p> <p>To register a function, use the <a class="reference internal" href="#flask.Blueprint.url_defaults" title="flask.Blueprint.url_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">url_defaults()</span></code></a> decorator.</p> <p>This data structure is internal. It should not be modified directly and its format may change at any time.</p> </dd></dl> </dd></dl> </section> <section id="incoming-request-data"> <h2>Incoming Request Data<a class="headerlink" href="#incoming-request-data" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.Request"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">Request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">populate_request</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">shallow</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request" title="Link to this definition">¶</a></dt> <dd><p>The request object used by default in Flask. Remembers the matched endpoint and view arguments.</p> <p>It is what ends up as <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-class docutils literal notranslate"><span class="pre">request</span></code></a>. If you want to replace the request object used you can subclass this and set <a class="reference internal" href="#flask.Flask.request_class" title="flask.Flask.request_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">request_class</span></code></a> to your subclass.</p> <p>The request object is a <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Request" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>environ</strong> (<em>WSGIEnvironment</em>)</p></li> <li><p><strong>populate_request</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>shallow</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.url_rule"> <span class="sig-name descname"><span class="pre">url_rule</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">Rule</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Request.url_rule" title="Link to this definition">¶</a></dt> <dd><p>The internal URL rule that matched the request. This can be useful to inspect which methods are allowed for the URL from a before/after handler (<code class="docutils literal notranslate"><span class="pre">request.url_rule.methods</span></code>) etc. Though if the request’s method was invalid for the URL rule, the valid list is available in <code class="docutils literal notranslate"><span class="pre">routing_exception.valid_methods</span></code> instead (an attribute of the Werkzeug exception <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.MethodNotAllowed" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">MethodNotAllowed</span></code></a>) because the request was never internally bound.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.view_args"> <span class="sig-name descname"><span class="pre">view_args</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Request.view_args" title="Link to this definition">¶</a></dt> <dd><p>A dict of view arguments that matched the request. If an exception happened when matching, this will be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.routing_exception"> <span class="sig-name descname"><span class="pre">routing_exception</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">HTTPException</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Request.routing_exception" title="Link to this definition">¶</a></dt> <dd><p>If matching the URL failed, this is the exception that will be raised / was raised as part of the request handling. This is usually a <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.NotFound" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFound</span></code></a> exception or something similar.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.max_content_length"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">max_content_length</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.max_content_length" title="Link to this definition">¶</a></dt> <dd><p>The maximum number of bytes that will be read during this request. If this limit is exceeded, a 413 <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.RequestEntityTooLarge" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code></a> error is raised. If it is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, no limit is enforced at the Flask application level. However, if it is <code class="docutils literal notranslate"><span class="pre">None</span></code> and the request has no <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> header and the WSGI server does not indicate that it terminates the stream, then no data is read to avoid an infinite stream.</p> <p>Each request defaults to the <a class="reference internal" href="../config/#MAX_CONTENT_LENGTH" title="MAX_CONTENT_LENGTH"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_CONTENT_LENGTH</span></code></a> config, which defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code>. It can be set on a specific <code class="docutils literal notranslate"><span class="pre">request</span></code> to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>This can be set per-request.</p> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.6: </span>This is configurable through Flask config.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.max_form_memory_size"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">max_form_memory_size</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.max_form_memory_size" title="Link to this definition">¶</a></dt> <dd><p>The maximum size in bytes any non-file form field may be in a <code class="docutils literal notranslate"><span class="pre">multipart/form-data</span></code> body. If this limit is exceeded, a 413 <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.RequestEntityTooLarge" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code></a> error is raised. If it is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, no limit is enforced at the Flask application level.</p> <p>Each request defaults to the <a class="reference internal" href="../config/#MAX_FORM_MEMORY_SIZE" title="MAX_FORM_MEMORY_SIZE"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_FORM_MEMORY_SIZE</span></code></a> config, which defaults to <code class="docutils literal notranslate"><span class="pre">500_000</span></code>. It can be set on a specific <code class="docutils literal notranslate"><span class="pre">request</span></code> to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>This is configurable through Flask config.</p> </div> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.max_form_parts"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">max_form_parts</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.max_form_parts" title="Link to this definition">¶</a></dt> <dd><p>The maximum number of fields that may be present in a <code class="docutils literal notranslate"><span class="pre">multipart/form-data</span></code> body. If this limit is exceeded, a 413 <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.RequestEntityTooLarge" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RequestEntityTooLarge</span></code></a> error is raised. If it is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>, no limit is enforced at the Flask application level.</p> <p>Each request defaults to the <a class="reference internal" href="../config/#MAX_FORM_PARTS" title="MAX_FORM_PARTS"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_FORM_PARTS</span></code></a> config, which defaults to <code class="docutils literal notranslate"><span class="pre">1_000</span></code>. It can be set on a specific <code class="docutils literal notranslate"><span class="pre">request</span></code> to apply the limit to that specific view. This should be set appropriately based on an application’s or view’s specific needs.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>This is configurable through Flask config.</p> </div> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.endpoint"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">endpoint</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.endpoint" title="Link to this definition">¶</a></dt> <dd><p>The endpoint that matched the request URL.</p> <p>This will be <code class="docutils literal notranslate"><span class="pre">None</span></code> if matching failed or has not been performed yet.</p> <p>This in combination with <a class="reference internal" href="#flask.Request.view_args" title="flask.Request.view_args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">view_args</span></code></a> can be used to reconstruct the same URL or a modified URL.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.blueprint"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">blueprint</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.blueprint" title="Link to this definition">¶</a></dt> <dd><p>The registered name of the current blueprint.</p> <p>This will be <code class="docutils literal notranslate"><span class="pre">None</span></code> if the endpoint is not part of a blueprint, or if URL matching failed or has not been performed yet.</p> <p>This does not necessarily match the name the blueprint was created with. It may have been nested, or registered with a different name.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.blueprints"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">blueprints</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.blueprints" title="Link to this definition">¶</a></dt> <dd><p>The registered names of the current blueprint upwards through parent blueprints.</p> <p>This will be an empty list if there is no current blueprint, or if URL matching failed.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.1.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.on_json_loading_failed"> <span class="sig-name descname"><span class="pre">on_json_loading_failed</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.on_json_loading_failed" title="Link to this definition">¶</a></dt> <dd><p>Called if <a class="reference internal" href="#flask.Request.get_json" title="flask.Request.get_json"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_json()</span></code></a> fails and isn’t silenced.</p> <p>If this method returns a value, it is used as the return value for <a class="reference internal" href="#flask.Request.get_json" title="flask.Request.get_json"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_json()</span></code></a>. The default implementation raises <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.BadRequest" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BadRequest</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>e</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><em>ValueError</em></a><em> | </em><em>None</em>) – If parsing failed, this is the exception. It will be <code class="docutils literal notranslate"><span class="pre">None</span></code> if the content type wasn’t <code class="docutils literal notranslate"><span class="pre">application/json</span></code>.</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Raise a 415 error instead of 400.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.accept_charsets"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">accept_charsets</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.CharsetAccept" title="(in Werkzeug v3.1.x)"><span class="pre">CharsetAccept</span></a></em><a class="headerlink" href="#flask.Request.accept_charsets" title="Link to this definition">¶</a></dt> <dd><p>List of charsets this client supports as <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.CharsetAccept" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">CharsetAccept</span></code></a> object.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.accept_encodings"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">accept_encodings</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Accept" title="(in Werkzeug v3.1.x)"><span class="pre">Accept</span></a></em><a class="headerlink" href="#flask.Request.accept_encodings" title="Link to this definition">¶</a></dt> <dd><p>List of encodings this client accepts. Encodings in a HTTP term are compression encodings such as gzip. For charsets have a look at <code class="xref py py-attr docutils literal notranslate"><span class="pre">accept_charset</span></code>.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.accept_languages"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">accept_languages</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.LanguageAccept" title="(in Werkzeug v3.1.x)"><span class="pre">LanguageAccept</span></a></em><a class="headerlink" href="#flask.Request.accept_languages" title="Link to this definition">¶</a></dt> <dd><p>List of languages this client accepts as <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.LanguageAccept" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">LanguageAccept</span></code></a> object.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.accept_mimetypes"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">accept_mimetypes</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.MIMEAccept" title="(in Werkzeug v3.1.x)"><span class="pre">MIMEAccept</span></a></em><a class="headerlink" href="#flask.Request.accept_mimetypes" title="Link to this definition">¶</a></dt> <dd><p>List of mimetypes this client supports as <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.MIMEAccept" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">MIMEAccept</span></code></a> object.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.access_control_request_headers"> <span class="sig-name descname"><span class="pre">access_control_request_headers</span></span><a class="headerlink" href="#flask.Request.access_control_request_headers" title="Link to this definition">¶</a></dt> <dd><p>Sent with a preflight request to indicate which headers will be sent with the cross origin request. Set <code class="xref py py-attr docutils literal notranslate"><span class="pre">access_control_allow_headers</span></code> on the response to indicate which headers are allowed.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.access_control_request_method"> <span class="sig-name descname"><span class="pre">access_control_request_method</span></span><a class="headerlink" href="#flask.Request.access_control_request_method" title="Link to this definition">¶</a></dt> <dd><p>Sent with a preflight request to indicate which method will be used for the cross origin request. Set <code class="xref py py-attr docutils literal notranslate"><span class="pre">access_control_allow_methods</span></code> on the response to indicate which methods are allowed.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.access_route"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">access_route</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.access_route" title="Link to this definition">¶</a></dt> <dd><p>If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.application"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">application</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.application" title="Link to this definition">¶</a></dt> <dd><p>Decorate a function as responder that accepts the request as the last argument. This works like the <code class="xref py py-func docutils literal notranslate"><span class="pre">responder()</span></code> decorator but the function is passed the request object as the last argument and the request object will be closed automatically:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Request</span><span class="o">.</span><span class="n">application</span> <span class="k">def</span> <span class="nf">my_wsgi_app</span><span class="p">(</span><span class="n">request</span><span class="p">):</span> <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="s1">&#39;Hello World!&#39;</span><span class="p">)</span> </pre></div> </div> <p>As of Werkzeug 0.14 HTTP exceptions are automatically caught and converted to responses instead of failing.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>t.Callable</em><em>[</em><em>[</em><a class="reference internal" href="#flask.Request" title="flask.Request"><em>Request</em></a><em>]</em><em>, </em><em>WSGIApplication</em><em>]</em>) – the WSGI callable to decorate</p> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a new WSGI callable</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>WSGIApplication</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.args"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">args</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.MultiDict" title="(in Werkzeug v3.1.x)"><span class="pre">MultiDict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.args" title="Link to this definition">¶</a></dt> <dd><p>The parsed URL parameters (the part in the URL after the question mark).</p> <p>By default an <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ImmutableMultiDict" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImmutableMultiDict</span></code></a> is returned from this function. This can be changed by setting <a class="reference internal" href="#flask.Request.parameter_storage_class" title="flask.Request.parameter_storage_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">parameter_storage_class</span></code></a> to a different type. This might be necessary if the order of the form data is important.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Invalid bytes remain percent encoded.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.authorization"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">authorization</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Authorization" title="(in Werkzeug v3.1.x)"><span class="pre">Authorization</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.authorization" title="Link to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">Authorization</span></code> header parsed into an <code class="xref py py-class docutils literal notranslate"><span class="pre">Authorization</span></code> object. <code class="docutils literal notranslate"><span class="pre">None</span></code> if the header is not present.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span><code class="xref py py-class docutils literal notranslate"><span class="pre">Authorization</span></code> is no longer a <code class="docutils literal notranslate"><span class="pre">dict</span></code>. The <code class="docutils literal notranslate"><span class="pre">token</span></code> attribute was added for auth schemes that use a token instead of parameters.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.base_url"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">base_url</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.base_url" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Request.url" title="flask.Request.url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">url</span></code></a> but without the query string.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.cache_control"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">cache_control</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.RequestCacheControl" title="(in Werkzeug v3.1.x)"><span class="pre">RequestCacheControl</span></a></em><a class="headerlink" href="#flask.Request.cache_control" title="Link to this definition">¶</a></dt> <dd><p>A <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.RequestCacheControl" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestCacheControl</span></code></a> object for the incoming cache control headers.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.close"> <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.close" title="Link to this definition">¶</a></dt> <dd><p>Closes associated resources of this request object. This closes all file handles explicitly. You can also use the request object in a with statement which will automatically close it.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.content_encoding"> <span class="sig-name descname"><span class="pre">content_encoding</span></span><a class="headerlink" href="#flask.Request.content_encoding" title="Link to this definition">¶</a></dt> <dd><p>The Content-Encoding entity-header field is used as a modifier to the media-type. When present, its value indicates what additional content codings have been applied to the entity-body, and thus what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header field.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.content_length"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">content_length</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.content_length" title="Link to this definition">¶</a></dt> <dd><p>The Content-Length entity-header field indicates the size of the entity-body in bytes or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.content_md5"> <span class="sig-name descname"><span class="pre">content_md5</span></span><a class="headerlink" href="#flask.Request.content_md5" title="Link to this definition">¶</a></dt> <dd><p>The Content-MD5 entity-header field, as defined in RFC 1864, is an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body. (Note: a MIC is good for detecting accidental modification of the entity-body in transit, but is not proof against malicious attacks.)</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.content_type"> <span class="sig-name descname"><span class="pre">content_type</span></span><a class="headerlink" href="#flask.Request.content_type" title="Link to this definition">¶</a></dt> <dd><p>The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.cookies"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">cookies</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ImmutableMultiDict</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.cookies" title="Link to this definition">¶</a></dt> <dd><p>A <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> with the contents of all cookies transmitted with the request.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.data"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">data</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><span class="pre">bytes</span></a></em><a class="headerlink" href="#flask.Request.data" title="Link to this definition">¶</a></dt> <dd><p>The raw data read from <a class="reference internal" href="#flask.Request.stream" title="flask.Request.stream"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stream</span></code></a>. Will be empty if the request represents form data.</p> <p>To get the raw data even if it represents form data, use <a class="reference internal" href="#flask.Request.get_data" title="flask.Request.get_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_data()</span></code></a>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.date"> <span class="sig-name descname"><span class="pre">date</span></span><a class="headerlink" href="#flask.Request.date" title="Link to this definition">¶</a></dt> <dd><p>The Date general-header field represents the date and time at which the message was originated, having the same semantics as orig-date in RFC 822.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.dict_storage_class"> <span class="sig-name descname"><span class="pre">dict_storage_class</span></span><a class="headerlink" href="#flask.Request.dict_storage_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <code class="xref py py-class docutils literal notranslate"><span class="pre">ImmutableMultiDict</span></code></p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.files"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">files</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ImmutableMultiDict</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage" title="(in Werkzeug v3.1.x)"><span class="pre">FileStorage</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.files" title="Link to this definition">¶</a></dt> <dd><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.MultiDict" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code></a> object containing all uploaded files. Each key in <a class="reference internal" href="#flask.Request.files" title="flask.Request.files"><code class="xref py py-attr docutils literal notranslate"><span class="pre">files</span></code></a> is the name from the <code class="docutils literal notranslate"><span class="pre">&lt;input</span> <span class="pre">type=&quot;file&quot;</span> <span class="pre">name=&quot;&quot;&gt;</span></code>. Each value in <a class="reference internal" href="#flask.Request.files" title="flask.Request.files"><code class="xref py py-attr docutils literal notranslate"><span class="pre">files</span></code></a> is a Werkzeug <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileStorage</span></code></a> object.</p> <p>It basically behaves like a standard file object you know from Python, with the difference that it also has a <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage.save" title="(in Werkzeug v3.1.x)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">save()</span></code></a> function that can store the file on the filesystem.</p> <p>Note that <a class="reference internal" href="#flask.Request.files" title="flask.Request.files"><code class="xref py py-attr docutils literal notranslate"><span class="pre">files</span></code></a> will only contain data if the request method was POST, PUT or PATCH and the <code class="docutils literal notranslate"><span class="pre">&lt;form&gt;</span></code> that posted to the request had <code class="docutils literal notranslate"><span class="pre">enctype=&quot;multipart/form-data&quot;</span></code>. It will be empty otherwise.</p> <p>See the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.MultiDict" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">MultiDict</span></code></a> / <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.FileStorage" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileStorage</span></code></a> documentation for more details about the used data structure.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.form"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">form</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ImmutableMultiDict</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.form" title="Link to this definition">¶</a></dt> <dd><p>The form parameters. By default an <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ImmutableMultiDict" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImmutableMultiDict</span></code></a> is returned from this function. This can be changed by setting <a class="reference internal" href="#flask.Request.parameter_storage_class" title="flask.Request.parameter_storage_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">parameter_storage_class</span></code></a> to a different type. This might be necessary if the order of the form data is important.</p> <p>Please keep in mind that file uploads will not end up here, but instead in the <a class="reference internal" href="#flask.Request.files" title="flask.Request.files"><code class="xref py py-attr docutils literal notranslate"><span class="pre">files</span></code></a> attribute.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>Previous to Werkzeug 0.9 this would only contain form data for POST and PUT requests.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.form_data_parser_class"> <span class="sig-name descname"><span class="pre">form_data_parser_class</span></span><a class="headerlink" href="#flask.Request.form_data_parser_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/http/#werkzeug.formparser.FormDataParser" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">FormDataParser</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.from_values"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">from_values</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.from_values" title="Link to this definition">¶</a></dt> <dd><p>Create a new request object based on the values provided. If environ is given missing values are filled from there. This method is useful for small scripts when you need to simulate a request from an URL. Do not use this method for unittesting, there is a full featured client object (<code class="xref py py-class docutils literal notranslate"><span class="pre">Client</span></code>) that allows to create multipart requests, support for cookies etc.</p> <p>This accepts the same options as the <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.EnvironBuilder" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.5: </span>This method now accepts the same arguments as <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.EnvironBuilder" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code></a>. Because of this the <code class="code docutils literal notranslate"><span class="pre">environ</span></code> parameter is now called <code class="code docutils literal notranslate"><span class="pre">environ_overrides</span></code>.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Returns<span class="colon">:</span></dt> <dd class="field-odd"><p>request object</p> </dd> <dt class="field-even">Parameters<span class="colon">:</span></dt> <dd class="field-even"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Request" title="(in Werkzeug v3.1.x)"><em>Request</em></a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.full_path"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">full_path</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.full_path" title="Link to this definition">¶</a></dt> <dd><p>Requested path, including the query string.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.get_data"> <span class="sig-name descname"><span class="pre">get_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cache</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">as_text</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parse_form_data</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.get_data" title="Link to this definition">¶</a></dt> <dd><p>This reads the buffered incoming data from the client into one bytes object. By default this is cached but that behavior can be changed by setting <code class="code docutils literal notranslate"><span class="pre">cache</span></code> to <code class="code docutils literal notranslate"><span class="pre">False</span></code>.</p> <p>Usually it’s a bad idea to call this method without checking the content length first as a client could send dozens of megabytes or more to cause memory problems on the server.</p> <p>Note that if the form data was already parsed this method will not return anything as form data parsing does not cache the data like this method does. To implicitly invoke form data parsing function set <code class="code docutils literal notranslate"><span class="pre">parse_form_data</span></code> to <code class="code docutils literal notranslate"><span class="pre">True</span></code>. When this is done the return value of this method will be an empty string if the form parser handles the data. This generally is not necessary as if the whole data is cached (which is the default) the form parser will used the cached data to parse the form data. Please be generally aware of checking the content length first in any case before calling this method to avoid exhausting server memory.</p> <p>If <code class="code docutils literal notranslate"><span class="pre">as_text</span></code> is set to <code class="code docutils literal notranslate"><span class="pre">True</span></code> the return value will be a decoded string.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>cache</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>as_text</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>parse_form_data</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a> | <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.get_json"> <span class="sig-name descname"><span class="pre">get_json</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">silent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.get_json" title="Link to this definition">¶</a></dt> <dd><p>Parse <a class="reference internal" href="#flask.Request.data" title="flask.Request.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a> as JSON.</p> <p>If the mimetype does not indicate JSON (<em class="mimetype">application/json</em>, see <a class="reference internal" href="#flask.Request.is_json" title="flask.Request.is_json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_json</span></code></a>), or parsing fails, <a class="reference internal" href="#flask.Request.on_json_loading_failed" title="flask.Request.on_json_loading_failed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">on_json_loading_failed()</span></code></a> is called and its return value is used as the return value. By default this raises a 415 Unsupported Media Type resp.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>force</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Ignore the mimetype and always try to parse JSON.</p></li> <li><p><strong>silent</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Silence mimetype and parsing errors, and return <code class="docutils literal notranslate"><span class="pre">None</span></code> instead.</p></li> <li><p><strong>cache</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Store the parsed JSON to return for subsequent calls.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a> | None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Raise a 415 error instead of 400.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>Raise a 400 error if the content type is incorrect.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.host"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">host</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.host" title="Link to this definition">¶</a></dt> <dd><p>The host name the request was made to, including the port if it’s non-standard. Validated with <a class="reference internal" href="#flask.Request.trusted_hosts" title="flask.Request.trusted_hosts"><code class="xref py py-attr docutils literal notranslate"><span class="pre">trusted_hosts</span></code></a>.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.host_url"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">host_url</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.host_url" title="Link to this definition">¶</a></dt> <dd><p>The request URL scheme and host only.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.if_match"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">if_match</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ETags" title="(in Werkzeug v3.1.x)"><span class="pre">ETags</span></a></em><a class="headerlink" href="#flask.Request.if_match" title="Link to this definition">¶</a></dt> <dd><p>An object containing all the etags in the <code class="code docutils literal notranslate"><span class="pre">If-Match</span></code> header.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ETags" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ETags</span></code></a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.if_modified_since"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">if_modified_since</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><span class="pre">datetime</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.if_modified_since" title="Link to this definition">¶</a></dt> <dd><p>The parsed <code class="code docutils literal notranslate"><span class="pre">If-Modified-Since</span></code> header as a datetime object.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.if_none_match"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">if_none_match</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ETags" title="(in Werkzeug v3.1.x)"><span class="pre">ETags</span></a></em><a class="headerlink" href="#flask.Request.if_none_match" title="Link to this definition">¶</a></dt> <dd><p>An object containing all the etags in the <code class="code docutils literal notranslate"><span class="pre">If-None-Match</span></code> header.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ETags" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ETags</span></code></a></p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.if_range"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">if_range</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.IfRange" title="(in Werkzeug v3.1.x)"><span class="pre">IfRange</span></a></em><a class="headerlink" href="#flask.Request.if_range" title="Link to this definition">¶</a></dt> <dd><p>The parsed <code class="docutils literal notranslate"><span class="pre">If-Range</span></code> header.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">IfRange.date</span></code> is timezone-aware.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.if_unmodified_since"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">if_unmodified_since</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><span class="pre">datetime</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.if_unmodified_since" title="Link to this definition">¶</a></dt> <dd><p>The parsed <code class="code docutils literal notranslate"><span class="pre">If-Unmodified-Since</span></code> header as a datetime object.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.input_stream"> <span class="sig-name descname"><span class="pre">input_stream</span></span><a class="headerlink" href="#flask.Request.input_stream" title="Link to this definition">¶</a></dt> <dd><p>The raw WSGI input stream, without any safety checks.</p> <p>This is dangerous to use. It does not guard against infinite streams or reading past <a class="reference internal" href="#flask.Request.content_length" title="flask.Request.content_length"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content_length</span></code></a> or <a class="reference internal" href="#flask.Request.max_content_length" title="flask.Request.max_content_length"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_content_length</span></code></a>.</p> <p>Use <a class="reference internal" href="#flask.Request.stream" title="flask.Request.stream"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stream</span></code></a> instead.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.is_json"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_json</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Request.is_json" title="Link to this definition">¶</a></dt> <dd><p>Check if the mimetype indicates JSON data, either <em class="mimetype">application/json</em> or <em class="mimetype">application/*+json</em>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.is_multiprocess"> <span class="sig-name descname"><span class="pre">is_multiprocess</span></span><a class="headerlink" href="#flask.Request.is_multiprocess" title="Link to this definition">¶</a></dt> <dd><p>boolean that is <code class="code docutils literal notranslate"><span class="pre">True</span></code> if the application is served by a WSGI server that spawns multiple processes.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.is_multithread"> <span class="sig-name descname"><span class="pre">is_multithread</span></span><a class="headerlink" href="#flask.Request.is_multithread" title="Link to this definition">¶</a></dt> <dd><p>boolean that is <code class="code docutils literal notranslate"><span class="pre">True</span></code> if the application is served by a multithreaded WSGI server.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.is_run_once"> <span class="sig-name descname"><span class="pre">is_run_once</span></span><a class="headerlink" href="#flask.Request.is_run_once" title="Link to this definition">¶</a></dt> <dd><p>boolean that is <code class="code docutils literal notranslate"><span class="pre">True</span></code> if the application will be executed only once in a process lifetime. This is the case for CGI for example, but it’s not guaranteed that the execution only happens one time.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.is_secure"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_secure</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Request.is_secure" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the request was made with a secure protocol (HTTPS or WSS).</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.json"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">json</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><span class="pre">Any</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.json" title="Link to this definition">¶</a></dt> <dd><p>The parsed JSON data if <a class="reference internal" href="#flask.Request.mimetype" title="flask.Request.mimetype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mimetype</span></code></a> indicates JSON (<em class="mimetype">application/json</em>, see <a class="reference internal" href="#flask.Request.is_json" title="flask.Request.is_json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_json</span></code></a>).</p> <p>Calls <a class="reference internal" href="#flask.Request.get_json" title="flask.Request.get_json"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_json()</span></code></a> with default arguments.</p> <p>If the request content type is not <code class="docutils literal notranslate"><span class="pre">application/json</span></code>, this will raise a 415 Unsupported Media Type error.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Raise a 415 error instead of 400.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>Raise a 400 error if the content type is incorrect.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.list_storage_class"> <span class="sig-name descname"><span class="pre">list_storage_class</span></span><a class="headerlink" href="#flask.Request.list_storage_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ImmutableList" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ImmutableList</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Request.make_form_data_parser"> <span class="sig-name descname"><span class="pre">make_form_data_parser</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Request.make_form_data_parser" title="Link to this definition">¶</a></dt> <dd><p>Creates the form data parser. Instantiates the <a class="reference internal" href="#flask.Request.form_data_parser_class" title="flask.Request.form_data_parser_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form_data_parser_class</span></code></a> with some parameters.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/http/#werkzeug.formparser.FormDataParser" title="(in Werkzeug v3.1.x)"><em>FormDataParser</em></a></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.max_forwards"> <span class="sig-name descname"><span class="pre">max_forwards</span></span><a class="headerlink" href="#flask.Request.max_forwards" title="Link to this definition">¶</a></dt> <dd><p>The Max-Forwards request-header field provides a mechanism with the TRACE and OPTIONS methods to limit the number of proxies or gateways that can forward the request to the next inbound server.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.mimetype"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">mimetype</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.mimetype" title="Link to this definition">¶</a></dt> <dd><p>Like <a class="reference internal" href="#flask.Request.content_type" title="flask.Request.content_type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content_type</span></code></a>, but without parameters (eg, without charset, type etc.) and always lowercase. For example if the content type is <code class="docutils literal notranslate"><span class="pre">text/HTML;</span> <span class="pre">charset=utf-8</span></code> the mimetype would be <code class="docutils literal notranslate"><span class="pre">'text/html'</span></code>.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.mimetype_params"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">mimetype_params</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.mimetype_params" title="Link to this definition">¶</a></dt> <dd><p>The mimetype parameters as dict. For example if the content type is <code class="docutils literal notranslate"><span class="pre">text/html;</span> <span class="pre">charset=utf-8</span></code> the params would be <code class="docutils literal notranslate"><span class="pre">{'charset':</span> <span class="pre">'utf-8'}</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.origin"> <span class="sig-name descname"><span class="pre">origin</span></span><a class="headerlink" href="#flask.Request.origin" title="Link to this definition">¶</a></dt> <dd><p>The host that the request originated from. Set <code class="xref py py-attr docutils literal notranslate"><span class="pre">access_control_allow_origin</span></code> on the response to indicate which origins are allowed.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.parameter_storage_class"> <span class="sig-name descname"><span class="pre">parameter_storage_class</span></span><a class="headerlink" href="#flask.Request.parameter_storage_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <code class="xref py py-class docutils literal notranslate"><span class="pre">ImmutableMultiDict</span></code></p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.pragma"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">pragma</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.HeaderSet" title="(in Werkzeug v3.1.x)"><span class="pre">HeaderSet</span></a></em><a class="headerlink" href="#flask.Request.pragma" title="Link to this definition">¶</a></dt> <dd><p>The Pragma general-header field is used to include implementation-specific directives that might apply to any recipient along the request/response chain. All pragma directives specify optional behavior from the viewpoint of the protocol; however, some systems MAY require that behavior be consistent with the directives.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.range"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">range</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Range" title="(in Werkzeug v3.1.x)"><span class="pre">Range</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Request.range" title="Link to this definition">¶</a></dt> <dd><p>The parsed <code class="code docutils literal notranslate"><span class="pre">Range</span></code> header.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Range" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Range</span></code></a></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.referrer"> <span class="sig-name descname"><span class="pre">referrer</span></span><a class="headerlink" href="#flask.Request.referrer" title="Link to this definition">¶</a></dt> <dd><p>The Referer[sic] request-header field allows the client to specify, for the server’s benefit, the address (URI) of the resource from which the Request-URI was obtained (the “referrer”, although the header field is misspelled).</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.remote_user"> <span class="sig-name descname"><span class="pre">remote_user</span></span><a class="headerlink" href="#flask.Request.remote_user" title="Link to this definition">¶</a></dt> <dd><p>If the server supports user authentication, and the script is protected, this attribute contains the username the user has authenticated as.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.root_url"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">root_url</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.root_url" title="Link to this definition">¶</a></dt> <dd><p>The request URL scheme, host, and root path. This is the root that the application is accessed from.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.script_root"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">script_root</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.script_root" title="Link to this definition">¶</a></dt> <dd><p>Alias for <code class="xref py py-attr docutils literal notranslate"><span class="pre">self.root_path</span></code>. <code class="docutils literal notranslate"><span class="pre">environ[&quot;SCRIPT_ROOT&quot;]</span></code> without a trailing slash.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.stream"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">stream</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><span class="pre">IO</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><span class="pre">bytes</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.stream" title="Link to this definition">¶</a></dt> <dd><p>The WSGI input stream, with safety checks. This stream can only be consumed once.</p> <p>Use <a class="reference internal" href="#flask.Request.get_data" title="flask.Request.get_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_data()</span></code></a> to get the full data as bytes or text. The <a class="reference internal" href="#flask.Request.data" title="flask.Request.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a> attribute will contain the full bytes only if they do not represent form data. The <a class="reference internal" href="#flask.Request.form" title="flask.Request.form"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form</span></code></a> attribute will contain the parsed form data in that case.</p> <p>Unlike <a class="reference internal" href="#flask.Request.input_stream" title="flask.Request.input_stream"><code class="xref py py-attr docutils literal notranslate"><span class="pre">input_stream</span></code></a>, this stream guards against infinite streams or reading past <a class="reference internal" href="#flask.Request.content_length" title="flask.Request.content_length"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content_length</span></code></a> or <a class="reference internal" href="#flask.Request.max_content_length" title="flask.Request.max_content_length"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_content_length</span></code></a>.</p> <p>If <code class="docutils literal notranslate"><span class="pre">max_content_length</span></code> is set, it can be enforced on streams if <code class="docutils literal notranslate"><span class="pre">wsgi.input_terminated</span></code> is set. Otherwise, an empty stream is returned.</p> <p>If the limit is reached before the underlying stream is exhausted (such as a file that is too large, or an infinite stream), the remaining contents of the stream cannot be read safely. Depending on how the server handles this, clients may show a “connection reset” failure instead of seeing the 413 response.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Check <code class="docutils literal notranslate"><span class="pre">max_content_length</span></code> preemptively and while reading.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>The stream is always set (but may be consumed) even if form parsing was accessed first.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.trusted_hosts"> <span class="sig-name descname"><span class="pre">trusted_hosts</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.Request.trusted_hosts" title="Link to this definition">¶</a></dt> <dd><p>Valid host names when handling requests. By default all hosts are trusted, which means that whatever the client says the host is will be accepted.</p> <p>Because <code class="docutils literal notranslate"><span class="pre">Host</span></code> and <code class="docutils literal notranslate"><span class="pre">X-Forwarded-Host</span></code> headers can be set to any value by a malicious client, it is recommended to either set this property or implement similar validation in the proxy (if the application is being run behind one).</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.url"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">url</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.url" title="Link to this definition">¶</a></dt> <dd><p>The full request URL with the scheme, host, root path, path, and query string.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.url_root"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">url_root</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Request.url_root" title="Link to this definition">¶</a></dt> <dd><p>Alias for <a class="reference internal" href="#flask.Request.root_url" title="flask.Request.root_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_url</span></code></a>. The URL with scheme, host, and root path. For example, <code class="docutils literal notranslate"><span class="pre">https://example.com/app/</span></code>.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.user_agent"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">user_agent</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.user_agent.UserAgent" title="(in Werkzeug v3.1.x)"><span class="pre">UserAgent</span></a></em><a class="headerlink" href="#flask.Request.user_agent" title="Link to this definition">¶</a></dt> <dd><p>The user agent. Use <code class="docutils literal notranslate"><span class="pre">user_agent.string</span></code> to get the header value. Set <a class="reference internal" href="#flask.Request.user_agent_class" title="flask.Request.user_agent_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">user_agent_class</span></code></a> to a subclass of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.user_agent.UserAgent" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserAgent</span></code></a> to provide parsing for the other properties or other extended data.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>The built-in parser was removed. Set <code class="docutils literal notranslate"><span class="pre">user_agent_class</span></code> to a <code class="docutils literal notranslate"><span class="pre">UserAgent</span></code> subclass to parse data from the string.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.user_agent_class"> <span class="sig-name descname"><span class="pre">user_agent_class</span></span><a class="headerlink" href="#flask.Request.user_agent_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.user_agent.UserAgent" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserAgent</span></code></a></p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.values"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">values</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.CombinedMultiDict" title="(in Werkzeug v3.1.x)"><span class="pre">CombinedMultiDict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Request.values" title="Link to this definition">¶</a></dt> <dd><p>A <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.CombinedMultiDict" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.datastructures.CombinedMultiDict</span></code></a> that combines <a class="reference internal" href="#flask.Request.args" title="flask.Request.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> and <a class="reference internal" href="#flask.Request.form" title="flask.Request.form"><code class="xref py py-attr docutils literal notranslate"><span class="pre">form</span></code></a>.</p> <p>For GET requests, only <code class="docutils literal notranslate"><span class="pre">args</span></code> are present, not <code class="docutils literal notranslate"><span class="pre">form</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>For GET requests, only <code class="docutils literal notranslate"><span class="pre">args</span></code> are present, not <code class="docutils literal notranslate"><span class="pre">form</span></code>.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Request.want_form_data_parsed"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">want_form_data_parsed</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Request.want_form_data_parsed" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the request method carries content. By default this is true if a <code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> is sent.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.environ"> <span class="sig-name descname"><span class="pre">environ</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">WSGIEnvironment</span></em><a class="headerlink" href="#flask.Request.environ" title="Link to this definition">¶</a></dt> <dd><p>The WSGI environment containing HTTP headers and information from the WSGI server.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.shallow"> <span class="sig-name descname"><span class="pre">shallow</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Request.shallow" title="Link to this definition">¶</a></dt> <dd><p>Set when creating the request object. If <code class="docutils literal notranslate"><span class="pre">True</span></code>, reading from the request body will cause a <code class="docutils literal notranslate"><span class="pre">RuntimeException</span></code>. Useful to prevent modifying the stream from middleware.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.method"> <span class="sig-name descname"><span class="pre">method</span></span><a class="headerlink" href="#flask.Request.method" title="Link to this definition">¶</a></dt> <dd><p>The method the request was made with, such as <code class="docutils literal notranslate"><span class="pre">GET</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.scheme"> <span class="sig-name descname"><span class="pre">scheme</span></span><a class="headerlink" href="#flask.Request.scheme" title="Link to this definition">¶</a></dt> <dd><p>The URL scheme of the protocol the request used, such as <code class="docutils literal notranslate"><span class="pre">https</span></code> or <code class="docutils literal notranslate"><span class="pre">wss</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.server"> <span class="sig-name descname"><span class="pre">server</span></span><a class="headerlink" href="#flask.Request.server" title="Link to this definition">¶</a></dt> <dd><p>The address of the server. <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code>, <code class="docutils literal notranslate"><span class="pre">(path,</span> <span class="pre">None)</span></code> for unix sockets, or <code class="docutils literal notranslate"><span class="pre">None</span></code> if not known.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.root_path"> <span class="sig-name descname"><span class="pre">root_path</span></span><a class="headerlink" href="#flask.Request.root_path" title="Link to this definition">¶</a></dt> <dd><p>The prefix that the application is mounted under, without a trailing slash. <a class="reference internal" href="#flask.Request.path" title="flask.Request.path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">path</span></code></a> comes after this.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.path"> <span class="sig-name descname"><span class="pre">path</span></span><a class="headerlink" href="#flask.Request.path" title="Link to this definition">¶</a></dt> <dd><p>The path part of the URL after <a class="reference internal" href="#flask.Request.root_path" title="flask.Request.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>. This is the path used for routing within the application.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.query_string"> <span class="sig-name descname"><span class="pre">query_string</span></span><a class="headerlink" href="#flask.Request.query_string" title="Link to this definition">¶</a></dt> <dd><p>The part of the URL after the “?”. This is the raw value, use <a class="reference internal" href="#flask.Request.args" title="flask.Request.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> for the parsed values.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.headers"> <span class="sig-name descname"><span class="pre">headers</span></span><a class="headerlink" href="#flask.Request.headers" title="Link to this definition">¶</a></dt> <dd><p>The headers received with the request.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Request.remote_addr"> <span class="sig-name descname"><span class="pre">remote_addr</span></span><a class="headerlink" href="#flask.Request.remote_addr" title="Link to this definition">¶</a></dt> <dd><p>The address of the client sending the request.</p> </dd></dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.request"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">request</span></span><a class="headerlink" href="#flask.request" title="Link to this definition">¶</a></dt> <dd><p>To access incoming request data, you can use the global <code class="code docutils literal notranslate"><span class="pre">request</span></code> object. Flask parses incoming request data for you and gives you access to it through that global object. Internally Flask makes sure that you always get the correct data for the active thread if you are in a multithreaded environment.</p> <p>This is a proxy. See <a class="reference internal" href="../reqcontext/#notes-on-proxies"><span class="std std-ref">Notes On Proxies</span></a> for more information.</p> <p>The request object is an instance of a <a class="reference internal" href="#flask.Request" title="flask.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a>.</p> </dd></dl> </section> <section id="response-objects"> <h2>Response Objects<a class="headerlink" href="#response-objects" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.Response"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">Response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">response</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">status</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">headers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mimetype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">content_type</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">direct_passthrough</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response" title="Link to this definition">¶</a></dt> <dd><p>The response object that is used by default in Flask. Works like the response object from Werkzeug but is set to have an HTML mimetype by default. Quite often you don’t have to create this object yourself because <a class="reference internal" href="#flask.Flask.make_response" title="flask.Flask.make_response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_response()</span></code></a> will take care of that for you.</p> <p>If you want to replace the response object used you can subclass this and set <a class="reference internal" href="#flask.Flask.response_class" title="flask.Flask.response_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">response_class</span></code></a> to your subclass.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>JSON support is added to the response, like the request. This is useful when testing to get the test client response data as JSON.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>Added <a class="reference internal" href="#flask.Response.max_cookie_size" title="flask.Response.max_cookie_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_cookie_size</span></code></a>.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>response</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterable" title="(in Python v3.13)"><em>Iterable</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterable" title="(in Python v3.13)"><em>Iterable</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a><em>]</em>)</p></li> <li><p><strong>status</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>HTTPStatus</em><em> | </em><em>None</em>)</p></li> <li><p><strong>headers</strong> (<a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Headers" title="(in Werkzeug v3.1.x)"><em>Headers</em></a>)</p></li> <li><p><strong>mimetype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>content_type</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>direct_passthrough</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.default_mimetype"> <span class="sig-name descname"><span class="pre">default_mimetype</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'text/html'</span></em><a class="headerlink" href="#flask.Response.default_mimetype" title="Link to this definition">¶</a></dt> <dd><p>the default mimetype if none is provided.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.accept_ranges"> <span class="sig-name descname"><span class="pre">accept_ranges</span></span><a class="headerlink" href="#flask.Response.accept_ranges" title="Link to this definition">¶</a></dt> <dd><p>The <code class="code docutils literal notranslate"><span class="pre">Accept-Ranges</span></code> header. Even though the name would indicate that multiple values are supported, it must be one string token only.</p> <p>The values <code class="docutils literal notranslate"><span class="pre">'bytes'</span></code> and <code class="docutils literal notranslate"><span class="pre">'none'</span></code> are common.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.access_control_allow_credentials"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">access_control_allow_credentials</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Response.access_control_allow_credentials" title="Link to this definition">¶</a></dt> <dd><p>Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.access_control_allow_headers"> <span class="sig-name descname"><span class="pre">access_control_allow_headers</span></span><a class="headerlink" href="#flask.Response.access_control_allow_headers" title="Link to this definition">¶</a></dt> <dd><p>Which headers can be sent with the cross origin request.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.access_control_allow_methods"> <span class="sig-name descname"><span class="pre">access_control_allow_methods</span></span><a class="headerlink" href="#flask.Response.access_control_allow_methods" title="Link to this definition">¶</a></dt> <dd><p>Which methods can be used for the cross origin request.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.access_control_allow_origin"> <span class="sig-name descname"><span class="pre">access_control_allow_origin</span></span><a class="headerlink" href="#flask.Response.access_control_allow_origin" title="Link to this definition">¶</a></dt> <dd><p>The origin or ‘*’ for any origin that may make cross origin requests.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.access_control_expose_headers"> <span class="sig-name descname"><span class="pre">access_control_expose_headers</span></span><a class="headerlink" href="#flask.Response.access_control_expose_headers" title="Link to this definition">¶</a></dt> <dd><p>Which headers can be shared by the browser to JavaScript code.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.access_control_max_age"> <span class="sig-name descname"><span class="pre">access_control_max_age</span></span><a class="headerlink" href="#flask.Response.access_control_max_age" title="Link to this definition">¶</a></dt> <dd><p>The maximum age in seconds the access control settings can be cached for.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.add_etag"> <span class="sig-name descname"><span class="pre">add_etag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">overwrite</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">weak</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.add_etag" title="Link to this definition">¶</a></dt> <dd><p>Add an etag for the current response if there is none yet.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>SHA-1 is used to generate the value. MD5 may not be available in some environments.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>overwrite</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>weak</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.age"> <span class="sig-name descname"><span class="pre">age</span></span><a class="headerlink" href="#flask.Response.age" title="Link to this definition">¶</a></dt> <dd><p>The Age response-header field conveys the sender’s estimate of the amount of time since the response (or its revalidation) was generated at the origin server.</p> <p>Age values are non-negative decimal integers, representing time in seconds.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.allow"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">allow</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.HeaderSet" title="(in Werkzeug v3.1.x)"><span class="pre">HeaderSet</span></a></em><a class="headerlink" href="#flask.Response.allow" title="Link to this definition">¶</a></dt> <dd><p>The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI. The purpose of this field is strictly to inform the recipient of valid methods associated with the resource. An Allow header field MUST be present in a 405 (Method Not Allowed) response.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.automatically_set_content_length"> <span class="sig-name descname"><span class="pre">automatically_set_content_length</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.Response.automatically_set_content_length" title="Link to this definition">¶</a></dt> <dd><p>Should this response object automatically set the content-length header if possible? This is true by default.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.cache_control"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">cache_control</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ResponseCacheControl" title="(in Werkzeug v3.1.x)"><span class="pre">ResponseCacheControl</span></a></em><a class="headerlink" href="#flask.Response.cache_control" title="Link to this definition">¶</a></dt> <dd><p>The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.calculate_content_length"> <span class="sig-name descname"><span class="pre">calculate_content_length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.calculate_content_length" title="Link to this definition">¶</a></dt> <dd><p>Returns the content length if available or <code class="code docutils literal notranslate"><span class="pre">None</span></code> otherwise.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)">int</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.call_on_close"> <span class="sig-name descname"><span class="pre">call_on_close</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.call_on_close" title="Link to this definition">¶</a></dt> <dd><p>Adds a function to the internal list of functions that should be called as part of closing down the response. Since 0.7 this function also returns the function that was passed so that this can be used as a decorator.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>func</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.close"> <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.close" title="Link to this definition">¶</a></dt> <dd><p>Close the wrapped response if possible. You can also use the object in a with statement which will automatically close it.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9: </span>Can now be used in a with statement.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.content_encoding"> <span class="sig-name descname"><span class="pre">content_encoding</span></span><a class="headerlink" href="#flask.Response.content_encoding" title="Link to this definition">¶</a></dt> <dd><p>The Content-Encoding entity-header field is used as a modifier to the media-type. When present, its value indicates what additional content codings have been applied to the entity-body, and thus what decoding mechanisms must be applied in order to obtain the media-type referenced by the Content-Type header field.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.content_language"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">content_language</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.HeaderSet" title="(in Werkzeug v3.1.x)"><span class="pre">HeaderSet</span></a></em><a class="headerlink" href="#flask.Response.content_language" title="Link to this definition">¶</a></dt> <dd><p>The Content-Language entity-header field describes the natural language(s) of the intended audience for the enclosed entity. Note that this might not be equivalent to all the languages used within the entity-body.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.content_length"> <span class="sig-name descname"><span class="pre">content_length</span></span><a class="headerlink" href="#flask.Response.content_length" title="Link to this definition">¶</a></dt> <dd><p>The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.content_location"> <span class="sig-name descname"><span class="pre">content_location</span></span><a class="headerlink" href="#flask.Response.content_location" title="Link to this definition">¶</a></dt> <dd><p>The Content-Location entity-header field MAY be used to supply the resource location for the entity enclosed in the message when that entity is accessible from a location separate from the requested resource’s URI.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.content_md5"> <span class="sig-name descname"><span class="pre">content_md5</span></span><a class="headerlink" href="#flask.Response.content_md5" title="Link to this definition">¶</a></dt> <dd><p>The Content-MD5 entity-header field, as defined in RFC 1864, is an MD5 digest of the entity-body for the purpose of providing an end-to-end message integrity check (MIC) of the entity-body. (Note: a MIC is good for detecting accidental modification of the entity-body in transit, but is not proof against malicious attacks.)</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.content_range"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">content_range</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ContentRange" title="(in Werkzeug v3.1.x)"><span class="pre">ContentRange</span></a></em><a class="headerlink" href="#flask.Response.content_range" title="Link to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">Content-Range</span></code> header as a <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.ContentRange" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ContentRange</span></code></a> object. Available even if the header is not set.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.content_security_policy"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">content_security_policy</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ContentSecurityPolicy</span></em><a class="headerlink" href="#flask.Response.content_security_policy" title="Link to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">Content-Security-Policy</span></code> header as a <code class="xref py py-class docutils literal notranslate"><span class="pre">ContentSecurityPolicy</span></code> object. Available even if the header is not set.</p> <p>The Content-Security-Policy header adds an additional layer of security to help detect and mitigate certain types of attacks.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.content_security_policy_report_only"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">content_security_policy_report_only</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ContentSecurityPolicy</span></em><a class="headerlink" href="#flask.Response.content_security_policy_report_only" title="Link to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">Content-Security-policy-report-only</span></code> header as a <code class="xref py py-class docutils literal notranslate"><span class="pre">ContentSecurityPolicy</span></code> object. Available even if the header is not set.</p> <p>The Content-Security-Policy-Report-Only header adds a csp policy that is not enforced but is reported thereby helping detect certain types of attacks.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.content_type"> <span class="sig-name descname"><span class="pre">content_type</span></span><a class="headerlink" href="#flask.Response.content_type" title="Link to this definition">¶</a></dt> <dd><p>The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.cross_origin_embedder_policy"> <span class="sig-name descname"><span class="pre">cross_origin_embedder_policy</span></span><a class="headerlink" href="#flask.Response.cross_origin_embedder_policy" title="Link to this definition">¶</a></dt> <dd><p>Prevents a document from loading any cross-origin resources that do not explicitly grant the document permission. Values must be a member of the <code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.http.COEP</span></code> enum.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.cross_origin_opener_policy"> <span class="sig-name descname"><span class="pre">cross_origin_opener_policy</span></span><a class="headerlink" href="#flask.Response.cross_origin_opener_policy" title="Link to this definition">¶</a></dt> <dd><p>Allows control over sharing of browsing context group with cross-origin documents. Values must be a member of the <code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.http.COOP</span></code> enum.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.data"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">data</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><span class="pre">bytes</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Response.data" title="Link to this definition">¶</a></dt> <dd><p>A descriptor that calls <a class="reference internal" href="#flask.Response.get_data" title="flask.Response.get_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_data()</span></code></a> and <a class="reference internal" href="#flask.Response.set_data" title="flask.Response.set_data"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_data()</span></code></a>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.date"> <span class="sig-name descname"><span class="pre">date</span></span><a class="headerlink" href="#flask.Response.date" title="Link to this definition">¶</a></dt> <dd><p>The Date general-header field represents the date and time at which the message was originated, having the same semantics as orig-date in RFC 822.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.default_status"> <span class="sig-name descname"><span class="pre">default_status</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">200</span></em><a class="headerlink" href="#flask.Response.default_status" title="Link to this definition">¶</a></dt> <dd><p>the default status if none is provided.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.delete_cookie"> <span class="sig-name descname"><span class="pre">delete_cookie</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'/'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">domain</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">httponly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">samesite</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">partitioned</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.delete_cookie" title="Link to this definition">¶</a></dt> <dd><p>Delete a cookie. Fails silently if key doesn’t exist.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>key</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the key (name) of the cookie to be deleted.</p></li> <li><p><strong>path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – if the cookie that should be deleted was limited to a path, the path has to be defined here.</p></li> <li><p><strong>domain</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – if the cookie that should be deleted was limited to a domain, that domain has to be defined here.</p></li> <li><p><strong>secure</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the cookie will only be available via HTTPS.</p></li> <li><p><strong>httponly</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Disallow JavaScript access to the cookie.</p></li> <li><p><strong>samesite</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – Limit the scope of the cookie to only be attached to requests that are “same-site”.</p></li> <li><p><strong>partitioned</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the cookie will be partitioned.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.expires"> <span class="sig-name descname"><span class="pre">expires</span></span><a class="headerlink" href="#flask.Response.expires" title="Link to this definition">¶</a></dt> <dd><p>The Expires entity-header field gives the date/time after which the response is considered stale. A stale cache entry may not normally be returned by a cache.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.force_type"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">force_type</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">response</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.force_type" title="Link to this definition">¶</a></dt> <dd><p>Enforce that the WSGI response is a response object of the current type. Werkzeug will use the <a class="reference internal" href="#flask.Response" title="flask.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> internally in many situations like the exceptions. If you call <code class="xref py py-meth docutils literal notranslate"><span class="pre">get_response()</span></code> on an exception you will get back a regular <a class="reference internal" href="#flask.Response" title="flask.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object, even if you are using a custom subclass.</p> <p>This method can enforce a given response type, and it will also convert arbitrary WSGI callables into response objects if an environ is provided:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># convert a Werkzeug response object into an instance of the</span> <span class="c1"># MyResponseClass subclass.</span> <span class="n">response</span> <span class="o">=</span> <span class="n">MyResponseClass</span><span class="o">.</span><span class="n">force_type</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> <span class="c1"># convert any WSGI application into a response object</span> <span class="n">response</span> <span class="o">=</span> <span class="n">MyResponseClass</span><span class="o">.</span><span class="n">force_type</span><span class="p">(</span><span class="n">response</span><span class="p">,</span> <span class="n">environ</span><span class="p">)</span> </pre></div> </div> <p>This is especially useful if you want to post-process responses in the main dispatcher and use functionality provided by your subclass.</p> <p>Keep in mind that this will modify response objects in place if possible!</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>response</strong> (<a class="reference internal" href="#flask.Response" title="flask.Response"><em>Response</em></a>) – a response object or wsgi application.</p></li> <li><p><strong>environ</strong> (<em>WSGIEnvironment</em><em> | </em><em>None</em>) – a WSGI environment object.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a response object.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.freeze"> <span class="sig-name descname"><span class="pre">freeze</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.freeze" title="Link to this definition">¶</a></dt> <dd><p>Make the response object ready to be pickled. Does the following:</p> <ul class="simple"> <li><p>Buffer the response into a list, ignoring <code class="xref py py-attr docutils literal notranslate"><span class="pre">implicity_sequence_conversion</span></code> and <a class="reference internal" href="#flask.Response.direct_passthrough" title="flask.Response.direct_passthrough"><code class="xref py py-attr docutils literal notranslate"><span class="pre">direct_passthrough</span></code></a>.</p></li> <li><p>Set the <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> header.</p></li> <li><p>Generate an <code class="docutils literal notranslate"><span class="pre">ETag</span></code> header if one is not already set.</p></li> </ul> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>Removed the <code class="docutils literal notranslate"><span class="pre">no_etag</span></code> parameter.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>An <code class="docutils literal notranslate"><span class="pre">ETag</span></code> header is always added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.6: </span>The <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> header is set.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.from_app"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">from_app</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffered</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.from_app" title="Link to this definition">¶</a></dt> <dd><p>Create a new response object from an application output. This works best if you pass it an application that returns a generator all the time. Sometimes applications may use the <code class="code docutils literal notranslate"><span class="pre">write()</span></code> callable returned by the <code class="code docutils literal notranslate"><span class="pre">start_response</span></code> function. This tries to resolve such edge cases automatically. But if you don’t get the expected output you should set <code class="code docutils literal notranslate"><span class="pre">buffered</span></code> to <code class="code docutils literal notranslate"><span class="pre">True</span></code> which enforces buffering.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<em>WSGIApplication</em>) – the WSGI application to execute.</p></li> <li><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – the WSGI environment to execute against.</p></li> <li><p><strong>buffered</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – set to <code class="code docutils literal notranslate"><span class="pre">True</span></code> to enforce buffering.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a response object.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_app_iter"> <span class="sig-name descname"><span class="pre">get_app_iter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_app_iter" title="Link to this definition">¶</a></dt> <dd><p>Returns the application iterator for the given environ. Depending on the request method and the current status code the return value might be an empty response rather than the one from the response.</p> <p>If the request method is <code class="code docutils literal notranslate"><span class="pre">HEAD</span></code> or the status code is in a range where the HTTP specification requires an empty response, an empty iterable is returned.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – the WSGI environment of the request.</p> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a response iterable.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>t.Iterable[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_data"> <span class="sig-name descname"><span class="pre">get_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">as_text</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_data" title="Link to this definition">¶</a></dt> <dd><p>The string representation of the response body. Whenever you call this property the response iterable is encoded and flattened. This can lead to unwanted behavior if you stream big data.</p> <p>This behavior can be disabled by setting <a class="reference internal" href="#flask.Response.implicit_sequence_conversion" title="flask.Response.implicit_sequence_conversion"><code class="xref py py-attr docutils literal notranslate"><span class="pre">implicit_sequence_conversion</span></code></a> to <code class="code docutils literal notranslate"><span class="pre">False</span></code>.</p> <p>If <code class="code docutils literal notranslate"><span class="pre">as_text</span></code> is set to <code class="code docutils literal notranslate"><span class="pre">True</span></code> the return value will be a decoded string.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>as_text</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a> | <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_etag"> <span class="sig-name descname"><span class="pre">get_etag</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_etag" title="Link to this definition">¶</a></dt> <dd><p>Return a tuple in the form <code class="docutils literal notranslate"><span class="pre">(etag,</span> <span class="pre">is_weak)</span></code>. If there is no ETag the return value is <code class="docutils literal notranslate"><span class="pre">(None,</span> <span class="pre">None)</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)">tuple</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a>] | <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)">tuple</a>[None, None]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_json"> <span class="sig-name descname"><span class="pre">get_json</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">silent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_json" title="Link to this definition">¶</a></dt> <dd><p>Parse <a class="reference internal" href="#flask.Response.data" title="flask.Response.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a> as JSON. Useful during testing.</p> <p>If the mimetype does not indicate JSON (<em class="mimetype">application/json</em>, see <a class="reference internal" href="#flask.Response.is_json" title="flask.Response.is_json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_json</span></code></a>), this returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> <p>Unlike <a class="reference internal" href="#flask.Request.get_json" title="flask.Request.get_json"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Request.get_json()</span></code></a>, the result is not cached.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>force</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Ignore the mimetype and always try to parse JSON.</p></li> <li><p><strong>silent</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Silence parsing errors and return <code class="docutils literal notranslate"><span class="pre">None</span></code> instead.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_wsgi_headers"> <span class="sig-name descname"><span class="pre">get_wsgi_headers</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_wsgi_headers" title="Link to this definition">¶</a></dt> <dd><p>This is automatically called right before the response is started and returns headers modified for the given environment. It returns a copy of the headers from the response with some modifications applied if necessary.</p> <p>For example the location header (if present) is joined with the root URL of the environment. Also the content length is automatically set to zero here for certain status codes.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.6: </span>Previously that function was called <code class="code docutils literal notranslate"><span class="pre">fix_headers</span></code> and modified the response object in place. Also since 0.6, IRIs in location and content-location headers are handled properly.</p> <p>Also starting with 0.6, Werkzeug will attempt to set the content length if it is able to figure it out on its own. This is the case if all the strings in the response iterable are already encoded and the iterable is buffered.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – the WSGI environment of the request.</p> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>returns a new <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.Headers" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Headers</span></code></a> object.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>Headers</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.get_wsgi_response"> <span class="sig-name descname"><span class="pre">get_wsgi_response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.get_wsgi_response" title="Link to this definition">¶</a></dt> <dd><p>Returns the final WSGI response as tuple. The first item in the tuple is the application iterator, the second the status and the third the list of headers. The response returned is created specially for the given environment. For example if the request method in the WSGI environment is <code class="docutils literal notranslate"><span class="pre">'HEAD'</span></code> the response will be empty and only the headers and status code will be present.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>environ</strong> (<em>WSGIEnvironment</em>) – the WSGI environment of the request.</p> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>an <code class="docutils literal notranslate"><span class="pre">(app_iter,</span> <span class="pre">status,</span> <span class="pre">headers)</span></code> tuple.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)">tuple</a>[t.Iterable[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a>], <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)">list</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)">tuple</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]]]</p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.implicit_sequence_conversion"> <span class="sig-name descname"><span class="pre">implicit_sequence_conversion</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.Response.implicit_sequence_conversion" title="Link to this definition">¶</a></dt> <dd><p>if set to <code class="code docutils literal notranslate"><span class="pre">False</span></code> accessing properties on the response object will not try to consume the response iterator and convert it into a list.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.2: </span>That attribute was previously called <code class="code docutils literal notranslate"><span class="pre">implicit_seqence_conversion</span></code>. (Notice the typo). If you did use this feature, you have to adapt your code to the name change.</p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.is_json"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_json</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Response.is_json" title="Link to this definition">¶</a></dt> <dd><p>Check if the mimetype indicates JSON data, either <em class="mimetype">application/json</em> or <em class="mimetype">application/*+json</em>.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.is_sequence"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_sequence</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Response.is_sequence" title="Link to this definition">¶</a></dt> <dd><p>If the iterator is buffered, this property will be <code class="code docutils literal notranslate"><span class="pre">True</span></code>. A response object will consider an iterator to be buffered if the response attribute is a list or tuple.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.is_streamed"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">is_streamed</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.Response.is_streamed" title="Link to this definition">¶</a></dt> <dd><p>If the response is streamed (the response is not an iterable with a length information) this property is <code class="code docutils literal notranslate"><span class="pre">True</span></code>. In this case streamed means that there is no information about the number of iterations. This is usually <code class="code docutils literal notranslate"><span class="pre">True</span></code> if a generator is passed to the response object.</p> <p>This is useful for checking before applying some sort of post filtering that should not take place for streamed responses.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.iter_encoded"> <span class="sig-name descname"><span class="pre">iter_encoded</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.iter_encoded" title="Link to this definition">¶</a></dt> <dd><p>Iter the response encoded with the encoding of the response. If the response object is invoked as WSGI application the return value of this method is used as application iterator unless <a class="reference internal" href="#flask.Response.direct_passthrough" title="flask.Response.direct_passthrough"><code class="xref py py-attr docutils literal notranslate"><span class="pre">direct_passthrough</span></code></a> was activated.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><em>Iterator</em></a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)">bytes</a>]</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.json"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">json</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><span class="pre">Any</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Response.json" title="Link to this definition">¶</a></dt> <dd><p>The parsed JSON data if <a class="reference internal" href="#flask.Response.mimetype" title="flask.Response.mimetype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mimetype</span></code></a> indicates JSON (<em class="mimetype">application/json</em>, see <a class="reference internal" href="#flask.Response.is_json" title="flask.Response.is_json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_json</span></code></a>).</p> <p>Calls <a class="reference internal" href="#flask.Response.get_json" title="flask.Response.get_json"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_json()</span></code></a> with default arguments.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.last_modified"> <span class="sig-name descname"><span class="pre">last_modified</span></span><a class="headerlink" href="#flask.Response.last_modified" title="Link to this definition">¶</a></dt> <dd><p>The Last-Modified entity-header field indicates the date and time at which the origin server believes the variant was last modified.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.location"> <span class="sig-name descname"><span class="pre">location</span></span><a class="headerlink" href="#flask.Response.location" title="Link to this definition">¶</a></dt> <dd><p>The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.make_conditional"> <span class="sig-name descname"><span class="pre">make_conditional</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">request_or_environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">accept_ranges</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">complete_length</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.make_conditional" title="Link to this definition">¶</a></dt> <dd><p>Make the response conditional to the request. This method works best if an etag was defined for the response already. The <code class="code docutils literal notranslate"><span class="pre">add_etag</span></code> method can be used to do that. If called without etag just the date header is set.</p> <p>This does nothing if the request method in the request or environ is anything but GET or HEAD.</p> <p>For optimal performance when handling range requests, it’s recommended that your response data object implements <code class="code docutils literal notranslate"><span class="pre">seekable</span></code>, <code class="code docutils literal notranslate"><span class="pre">seek</span></code> and <code class="code docutils literal notranslate"><span class="pre">tell</span></code> methods as described by <a class="reference external" href="https://docs.python.org/3/library/io.html#io.IOBase" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.IOBase</span></code></a>. Objects returned by <code class="xref py py-meth docutils literal notranslate"><span class="pre">wrap_file()</span></code> automatically implement those methods.</p> <p>It does not remove the body of the response because that’s something the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__call__()</span></code> function does for us automatically.</p> <p>Returns self so that you can do <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">resp.make_conditional(req)</span></code> but modifies the object in-place.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>request_or_environ</strong> (<em>WSGIEnvironment</em><em> | </em><a class="reference internal" href="#flask.Request" title="flask.Request"><em>Request</em></a>) – a request object or WSGI environment to be used to make the response conditional against.</p></li> <li><p><strong>accept_ranges</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – This parameter dictates the value of <code class="code docutils literal notranslate"><span class="pre">Accept-Ranges</span></code> header. If <code class="docutils literal notranslate"><span class="pre">False</span></code> (default), the header is not set. If <code class="docutils literal notranslate"><span class="pre">True</span></code>, it will be set to <code class="docutils literal notranslate"><span class="pre">&quot;bytes&quot;</span></code>. If it’s a string, it will use this value.</p></li> <li><p><strong>complete_length</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>None</em>) – Will be used only in valid Range Requests. It will set <code class="code docutils literal notranslate"><span class="pre">Content-Range</span></code> complete length value and compute <code class="code docutils literal notranslate"><span class="pre">Content-Length</span></code> real value. This parameter is mandatory for successful Range Requests completion.</p></li> </ul> </dd> <dt class="field-even">Raises<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.RequestedRangeNotSatisfiable" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestedRangeNotSatisfiable</span></code></a> if <code class="code docutils literal notranslate"><span class="pre">Range</span></code> header could not be parsed or satisfied.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>Range processing is skipped if length is 0 instead of raising a 416 Range Not Satisfiable error.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.make_sequence"> <span class="sig-name descname"><span class="pre">make_sequence</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.make_sequence" title="Link to this definition">¶</a></dt> <dd><p>Converts the response iterator in a list. By default this happens automatically if required. If <code class="code docutils literal notranslate"><span class="pre">implicit_sequence_conversion</span></code> is disabled, this method is not automatically called and some properties might raise exceptions. This also encodes all the items.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.mimetype"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">mimetype</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Response.mimetype" title="Link to this definition">¶</a></dt> <dd><p>The mimetype (content type without charset etc.)</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.mimetype_params"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">mimetype_params</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Response.mimetype_params" title="Link to this definition">¶</a></dt> <dd><p>The mimetype parameters as dict. For example if the content type is <code class="docutils literal notranslate"><span class="pre">text/html;</span> <span class="pre">charset=utf-8</span></code> the params would be <code class="docutils literal notranslate"><span class="pre">{'charset':</span> <span class="pre">'utf-8'}</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.retry_after"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">retry_after</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><span class="pre">datetime</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><a class="headerlink" href="#flask.Response.retry_after" title="Link to this definition">¶</a></dt> <dd><p>The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client.</p> <p>Time in seconds until expiration or date.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The datetime object is timezone-aware.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.set_cookie"> <span class="sig-name descname"><span class="pre">set_cookie</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_age</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expires</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'/'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">domain</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">httponly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">samesite</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">partitioned</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.set_cookie" title="Link to this definition">¶</a></dt> <dd><p>Sets a cookie.</p> <p>A warning is raised if the size of the cookie header exceeds <a class="reference internal" href="#flask.Response.max_cookie_size" title="flask.Response.max_cookie_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_cookie_size</span></code></a>, but the header will still be set.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>key</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the key (name) of the cookie to be set.</p></li> <li><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the value of the cookie.</p></li> <li><p><strong>max_age</strong> (<a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.13)"><em>timedelta</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>None</em>) – should be a number of seconds, or <code class="code docutils literal notranslate"><span class="pre">None</span></code> (default) if the cookie should last only as long as the client’s browser session.</p></li> <li><p><strong>expires</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><em>datetime</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.13)"><em>float</em></a><em> | </em><em>None</em>) – should be a <code class="code docutils literal notranslate"><span class="pre">datetime</span></code> object or UNIX timestamp.</p></li> <li><p><strong>path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – limits the cookie to a given path, per default it will span the whole domain.</p></li> <li><p><strong>domain</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – if you want to set a cross-domain cookie. For example, <code class="docutils literal notranslate"><span class="pre">domain=&quot;example.com&quot;</span></code> will set a cookie that is readable by the domain <code class="docutils literal notranslate"><span class="pre">www.example.com</span></code>, <code class="docutils literal notranslate"><span class="pre">foo.example.com</span></code> etc. Otherwise, a cookie will only be readable by the domain that set it.</p></li> <li><p><strong>secure</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the cookie will only be available via HTTPS.</p></li> <li><p><strong>httponly</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Disallow JavaScript access to the cookie.</p></li> <li><p><strong>samesite</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – Limit the scope of the cookie to only be attached to requests that are “same-site”.</p></li> <li><p><strong>partitioned</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – If <code class="docutils literal notranslate"><span class="pre">True</span></code>, the cookie will be partitioned.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>The <code class="docutils literal notranslate"><span class="pre">partitioned</span></code> parameter was added.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.set_data"> <span class="sig-name descname"><span class="pre">set_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.set_data" title="Link to this definition">¶</a></dt> <dd><p>Sets a new string as response. The value must be a string or bytes. If a string is set it’s encoded to the charset of the response (utf-8 by default).</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Response.set_etag"> <span class="sig-name descname"><span class="pre">set_etag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">etag</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">weak</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Response.set_etag" title="Link to this definition">¶</a></dt> <dd><p>Set the etag, and override the old one if there was one.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>etag</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>weak</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.status"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">status</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><a class="headerlink" href="#flask.Response.status" title="Link to this definition">¶</a></dt> <dd><p>The HTTP status code as a string.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.status_code"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">status_code</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></em><a class="headerlink" href="#flask.Response.status_code" title="Link to this definition">¶</a></dt> <dd><p>The HTTP status code as a number.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.stream"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">stream</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">ResponseStream</span></em><a class="headerlink" href="#flask.Response.stream" title="Link to this definition">¶</a></dt> <dd><p>The response iterable as write-only stream.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.vary"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">vary</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.HeaderSet" title="(in Werkzeug v3.1.x)"><span class="pre">HeaderSet</span></a></em><a class="headerlink" href="#flask.Response.vary" title="Link to this definition">¶</a></dt> <dd><p>The Vary field value indicates the set of request-header fields that fully determines, while the response is fresh, whether a cache is permitted to use the response to reply to a subsequent request without revalidation.</p> </dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.www_authenticate"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">www_authenticate</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/datastructures/#werkzeug.datastructures.WWWAuthenticate" title="(in Werkzeug v3.1.x)"><span class="pre">WWWAuthenticate</span></a></em><a class="headerlink" href="#flask.Response.www_authenticate" title="Link to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">WWW-Authenticate</span></code> header parsed into a <code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code> object. Modifying the object will modify the header value.</p> <p>This header is not set by default. To set this header, assign an instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code> to this attribute.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">response</span><span class="o">.</span><span class="n">www_authenticate</span> <span class="o">=</span> <span class="n">WWWAuthenticate</span><span class="p">(</span> <span class="s2">&quot;basic&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;realm&quot;</span><span class="p">:</span> <span class="s2">&quot;Authentication Required&quot;</span><span class="p">}</span> <span class="p">)</span> </pre></div> </div> <p>Multiple values for this header can be sent to give the client multiple options. Assign a list to set multiple headers. However, modifying the items in the list will not automatically update the header values, and accessing this attribute will only ever return the first value.</p> <p>To unset this header, assign <code class="docutils literal notranslate"><span class="pre">None</span></code> or use <code class="docutils literal notranslate"><span class="pre">del</span></code>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>This attribute can be assigned to to set the header. A list can be assigned to set multiple header values. Use <code class="docutils literal notranslate"><span class="pre">del</span></code> to unset the header.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span><code class="xref py py-class docutils literal notranslate"><span class="pre">WWWAuthenticate</span></code> is no longer a <code class="docutils literal notranslate"><span class="pre">dict</span></code>. The <code class="docutils literal notranslate"><span class="pre">token</span></code> attribute was added for auth challenges that use a token instead of parameters.</p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.response"> <span class="sig-name descname"><span class="pre">response</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">t.Iterable</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">t.Iterable</span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><span class="pre">bytes</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.Response.response" title="Link to this definition">¶</a></dt> <dd><p>The response body to send as the WSGI iterable. A list of strings or bytes represents a fixed-length response, any other iterable is a streaming response. Strings are encoded to bytes as UTF-8.</p> <p>Do not set to a plain string or bytes, that will cause sending the response to be very inefficient as it will iterate one byte at a time.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.direct_passthrough"> <span class="sig-name descname"><span class="pre">direct_passthrough</span></span><a class="headerlink" href="#flask.Response.direct_passthrough" title="Link to this definition">¶</a></dt> <dd><p>Pass the response body directly through as the WSGI iterable. This can be used when the body is a binary file or other iterator of bytes, to skip some unnecessary checks. Use <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.utils.send_file" title="(in Werkzeug v3.1.x)"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_file()</span></code></a> instead of setting this manually.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.Response.autocorrect_location_header"> <span class="sig-name descname"><span class="pre">autocorrect_location_header</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">False</span></em><a class="headerlink" href="#flask.Response.autocorrect_location_header" title="Link to this definition">¶</a></dt> <dd><p>If a redirect <code class="docutils literal notranslate"><span class="pre">Location</span></code> header is a relative URL, make it an absolute URL, including scheme and domain.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>This is disabled by default, so responses will send relative redirects.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py property"> <dt class="sig sig-object py" id="flask.Response.max_cookie_size"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">max_cookie_size</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><span class="pre">int</span></a></em><a class="headerlink" href="#flask.Response.max_cookie_size" title="Link to this definition">¶</a></dt> <dd><p>Read-only view of the <a class="reference internal" href="../config/#MAX_COOKIE_SIZE" title="MAX_COOKIE_SIZE"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAX_COOKIE_SIZE</span></code></a> config key.</p> <p>See <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Response.max_cookie_size" title="(in Werkzeug v3.1.x)"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_cookie_size</span></code></a> in Werkzeug’s docs.</p> </dd></dl> </dd></dl> </section> <section id="sessions"> <h2>Sessions<a class="headerlink" href="#sessions" title="Link to this heading">¶</a></h2> <p>If you have set <a class="reference internal" href="#flask.Flask.secret_key" title="flask.Flask.secret_key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Flask.secret_key</span></code></a> (or configured it from <a class="reference internal" href="../config/#SECRET_KEY" title="SECRET_KEY"><code class="xref py py-data docutils literal notranslate"><span class="pre">SECRET_KEY</span></code></a>) you can use sessions in Flask applications. A session makes it possible to remember information from one request to another. The way Flask does this is by using a signed cookie. The user can look at the session contents, but can’t modify it unless they know the secret key, so make sure to set that to something complex and unguessable.</p> <p>To access the current session you can use the <a class="reference internal" href="#flask.session" title="flask.session"><code class="xref py py-class docutils literal notranslate"><span class="pre">session</span></code></a> object:</p> <dl class="py class"> <dt class="sig sig-object py" id="flask.session"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">session</span></span><a class="headerlink" href="#flask.session" title="Link to this definition">¶</a></dt> <dd><p>The session object works pretty much like an ordinary dict, with the difference that it keeps track of modifications.</p> <p>This is a proxy. See <a class="reference internal" href="../reqcontext/#notes-on-proxies"><span class="std std-ref">Notes On Proxies</span></a> for more information.</p> <p>The following attributes are interesting:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.session.new"> <span class="sig-name descname"><span class="pre">new</span></span><a class="headerlink" href="#flask.session.new" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the session is new, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.session.modified"> <span class="sig-name descname"><span class="pre">modified</span></span><a class="headerlink" href="#flask.session.modified" title="Link to this definition">¶</a></dt> <dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the session object detected a modification. Be advised that modifications on mutable structures are not picked up automatically, in that situation you have to explicitly set the attribute to <code class="docutils literal notranslate"><span class="pre">True</span></code> yourself. Here an example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># this change is not picked up because a mutable object (here</span> <span class="c1"># a list) is changed.</span> <span class="n">session</span><span class="p">[</span><span class="s1">&#39;objects&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span> <span class="c1"># so mark it as modified yourself</span> <span class="n">session</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="kc">True</span> </pre></div> </div> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.session.permanent"> <span class="sig-name descname"><span class="pre">permanent</span></span><a class="headerlink" href="#flask.session.permanent" title="Link to this definition">¶</a></dt> <dd><p>If set to <code class="docutils literal notranslate"><span class="pre">True</span></code> the session lives for <a class="reference internal" href="#flask.Flask.permanent_session_lifetime" title="flask.Flask.permanent_session_lifetime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">permanent_session_lifetime</span></code></a> seconds. The default is 31 days. If set to <code class="docutils literal notranslate"><span class="pre">False</span></code> (which is the default) the session will be deleted when the user closes the browser.</p> </dd></dl> </dd></dl> </section> <section id="session-interface"> <h2>Session Interface<a class="headerlink" href="#session-interface" title="Link to this heading">¶</a></h2> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><p>The session interface provides a simple way to replace the session implementation that Flask is using.</p> <dl class="py class"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.sessions.</span></span><span class="sig-name descname"><span class="pre">SessionInterface</span></span><a class="headerlink" href="#flask.sessions.SessionInterface" title="Link to this definition">¶</a></dt> <dd><p>The basic interface you have to implement in order to replace the default session interface which uses werkzeug’s securecookie implementation. The only methods you have to implement are <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_session()</span></code></a> and <a class="reference internal" href="#flask.sessions.SessionInterface.save_session" title="flask.sessions.SessionInterface.save_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">save_session()</span></code></a>, the others have useful defaults which you don’t need to change.</p> <p>The session object returned by the <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_session()</span></code></a> method has to provide a dictionary like interface plus the properties and methods from the <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">SessionMixin</span></code></a>. We recommend just subclassing a dict and adding that mixin:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Session</span><span class="p">(</span><span class="nb">dict</span><span class="p">,</span> <span class="n">SessionMixin</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> <p>If <a class="reference internal" href="#flask.sessions.SessionInterface.open_session" title="flask.sessions.SessionInterface.open_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open_session()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">None</span></code> Flask will call into <a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session" title="flask.sessions.SessionInterface.make_null_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_null_session()</span></code></a> to create a session that acts as replacement if the session support cannot work because some requirement is not fulfilled. The default <a class="reference internal" href="#flask.sessions.NullSession" title="flask.sessions.NullSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullSession</span></code></a> class that is created will complain that the secret key was not set.</p> <p>To replace the session interface on an application all you have to do is to assign <a class="reference internal" href="#flask.Flask.session_interface" title="flask.Flask.session_interface"><code class="xref py py-attr docutils literal notranslate"><span class="pre">flask.Flask.session_interface</span></code></a>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> <span class="n">app</span><span class="o">.</span><span class="n">session_interface</span> <span class="o">=</span> <span class="n">MySessionInterface</span><span class="p">()</span> </pre></div> </div> <p>Multiple requests with the same session may be sent and handled concurrently. When implementing a new session interface, consider whether reads or writes to the backing store must be synchronized. There is no guarantee on the order in which the session for each request is opened or saved, it will occur in the order that requests begin and end processing.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details><dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.null_session_class"> <span class="sig-name descname"><span class="pre">null_session_class</span></span><a class="headerlink" href="#flask.sessions.SessionInterface.null_session_class" title="Link to this definition">¶</a></dt> <dd><p><a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session" title="flask.sessions.SessionInterface.make_null_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_null_session()</span></code></a> will look here for the class that should be created when a null session is requested. Likewise the <a class="reference internal" href="#flask.sessions.SessionInterface.is_null_session" title="flask.sessions.SessionInterface.is_null_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_null_session()</span></code></a> method will perform a typecheck against this type.</p> <p>alias of <a class="reference internal" href="#flask.sessions.NullSession" title="flask.sessions.NullSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullSession</span></code></a></p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.pickle_based"> <span class="sig-name descname"><span class="pre">pickle_based</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">False</span></em><a class="headerlink" href="#flask.sessions.SessionInterface.pickle_based" title="Link to this definition">¶</a></dt> <dd><p>A flag that indicates if the session interface is pickle based. This can be used by Flask extensions to make a decision in regards to how to deal with the session object.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.make_null_session"> <span class="sig-name descname"><span class="pre">make_null_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.make_null_session" title="Link to this definition">¶</a></dt> <dd><p>Creates a null session which acts as a replacement object if the real session support could not be loaded due to a configuration error. This mainly aids the user experience because the job of the null session is to still support lookup without complaining but modifications are answered with a helpful error message of what failed.</p> <p>This creates an instance of <a class="reference internal" href="#flask.sessions.SessionInterface.null_session_class" title="flask.sessions.SessionInterface.null_session_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">null_session_class</span></code></a> by default.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.sessions.NullSession" title="flask.sessions.NullSession">NullSession</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.is_null_session"> <span class="sig-name descname"><span class="pre">is_null_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.is_null_session" title="Link to this definition">¶</a></dt> <dd><p>Checks if a given object is a null session. Null sessions are not asked to be saved.</p> <p>This checks if the object is an instance of <a class="reference internal" href="#flask.sessions.SessionInterface.null_session_class" title="flask.sessions.SessionInterface.null_session_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">null_session_class</span></code></a> by default.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_name"> <span class="sig-name descname"><span class="pre">get_cookie_name</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_name" title="Link to this definition">¶</a></dt> <dd><p>The name of the session cookie. Uses``app.config[“SESSION_COOKIE_NAME”]``.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_domain"> <span class="sig-name descname"><span class="pre">get_cookie_domain</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_domain" title="Link to this definition">¶</a></dt> <dd><p>The value of the <code class="docutils literal notranslate"><span class="pre">Domain</span></code> parameter on the session cookie. If not set, browsers will only send the cookie to the exact domain it was set from. Otherwise, they will send it to any subdomain of the given value as well.</p> <p>Uses the <a class="reference internal" href="../config/#SESSION_COOKIE_DOMAIN" title="SESSION_COOKIE_DOMAIN"><code class="xref py py-data docutils literal notranslate"><span class="pre">SESSION_COOKIE_DOMAIN</span></code></a> config.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>Not set by default, does not fall back to <code class="docutils literal notranslate"><span class="pre">SERVER_NAME</span></code>.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_path"> <span class="sig-name descname"><span class="pre">get_cookie_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_path" title="Link to this definition">¶</a></dt> <dd><p>Returns the path for which the cookie should be valid. The default implementation uses the value from the <code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_PATH</span></code> config var if it’s set, and falls back to <code class="docutils literal notranslate"><span class="pre">APPLICATION_ROOT</span></code> or uses <code class="docutils literal notranslate"><span class="pre">/</span></code> if it’s <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_httponly"> <span class="sig-name descname"><span class="pre">get_cookie_httponly</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_httponly" title="Link to this definition">¶</a></dt> <dd><p>Returns True if the session cookie should be httponly. This currently just returns the value of the <code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_HTTPONLY</span></code> config var.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_secure"> <span class="sig-name descname"><span class="pre">get_cookie_secure</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_secure" title="Link to this definition">¶</a></dt> <dd><p>Returns True if the cookie should be secure. This currently just returns the value of the <code class="docutils literal notranslate"><span class="pre">SESSION_COOKIE_SECURE</span></code> setting.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_samesite"> <span class="sig-name descname"><span class="pre">get_cookie_samesite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_samesite" title="Link to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">'Strict'</span></code> or <code class="docutils literal notranslate"><span class="pre">'Lax'</span></code> if the cookie should use the <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> attribute. This currently just returns the value of the <a class="reference internal" href="../config/#SESSION_COOKIE_SAMESITE" title="SESSION_COOKIE_SAMESITE"><code class="xref py py-data docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a> setting.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_cookie_partitioned"> <span class="sig-name descname"><span class="pre">get_cookie_partitioned</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_cookie_partitioned" title="Link to this definition">¶</a></dt> <dd><p>Returns True if the cookie should be partitioned. By default, uses the value of <a class="reference internal" href="../config/#SESSION_COOKIE_PARTITIONED" title="SESSION_COOKIE_PARTITIONED"><code class="xref py py-data docutils literal notranslate"><span class="pre">SESSION_COOKIE_PARTITIONED</span></code></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">Added in version 3.1.</span></p> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.get_expiration_time"> <span class="sig-name descname"><span class="pre">get_expiration_time</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">session</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.get_expiration_time" title="Link to this definition">¶</a></dt> <dd><p>A helper method that returns an expiration date for the session or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the session is linked to the browser session. The default implementation returns now + the permanent session lifetime configured on the application.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>session</strong> (<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>datetime | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.should_set_cookie"> <span class="sig-name descname"><span class="pre">should_set_cookie</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">session</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.should_set_cookie" title="Link to this definition">¶</a></dt> <dd><p>Used by session backends to determine if a <code class="docutils literal notranslate"><span class="pre">Set-Cookie</span></code> header should be set for this session cookie for this response. If the session has been modified, the cookie is set. If the session is permanent and the <code class="docutils literal notranslate"><span class="pre">SESSION_REFRESH_EACH_REQUEST</span></code> config is true, the cookie is always set.</p> <p>This check is usually skipped if the session was deleted.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>session</strong> (<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.open_session"> <span class="sig-name descname"><span class="pre">open_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">request</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.open_session" title="Link to this definition">¶</a></dt> <dd><p>This is called at the beginning of each request, after pushing the request context, before matching the URL.</p> <p>This must return an object which implements a dictionary-like interface as well as the <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">SessionMixin</span></code></a> interface.</p> <p>This will return <code class="docutils literal notranslate"><span class="pre">None</span></code> to indicate that loading failed in some way that is not immediately an error. The request context will fall back to using <a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session" title="flask.sessions.SessionInterface.make_null_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_null_session()</span></code></a> in this case.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>request</strong> (<a class="reference internal" href="#flask.Request" title="flask.Request"><em>Request</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin">SessionMixin</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SessionInterface.save_session"> <span class="sig-name descname"><span class="pre">save_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">session</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SessionInterface.save_session" title="Link to this definition">¶</a></dt> <dd><p>This is called at the end of each request, after generating a response, before removing the request context. It is skipped if <a class="reference internal" href="#flask.sessions.SessionInterface.is_null_session" title="flask.sessions.SessionInterface.is_null_session"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_null_session()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>session</strong> (<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a>)</p></li> <li><p><strong>response</strong> (<a class="reference internal" href="#flask.Response" title="flask.Response"><em>Response</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.sessions.</span></span><span class="sig-name descname"><span class="pre">SecureCookieSessionInterface</span></span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface" title="Link to this definition">¶</a></dt> <dd><p>The default session interface that stores sessions in signed cookies through the <code class="xref py py-mod docutils literal notranslate"><span class="pre">itsdangerous</span></code> module.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.salt"> <span class="sig-name descname"><span class="pre">salt</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'cookie-session'</span></em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.salt" title="Link to this definition">¶</a></dt> <dd><p>the salt that should be applied on top of the secret key for the signing of cookie based sessions.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.digest_method"> <em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">digest_method</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">string</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">b''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.digest_method" title="Link to this definition">¶</a></dt> <dd><p>the hash function to use for the signature. The default is sha1</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>string</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.key_derivation"> <span class="sig-name descname"><span class="pre">key_derivation</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'hmac'</span></em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.key_derivation" title="Link to this definition">¶</a></dt> <dd><p>the name of the itsdangerous supported key derivation. The default is hmac.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.serializer"> <span class="sig-name descname"><span class="pre">serializer</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">&lt;flask.json.tag.TaggedJSONSerializer</span> <span class="pre">object&gt;</span></em><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.serializer" title="Link to this definition">¶</a></dt> <dd><p>A python serializer for the payload. The default is a compact JSON derived serializer with support for some extra Python types such as datetime objects or tuples.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.session_class"> <span class="sig-name descname"><span class="pre">session_class</span></span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.session_class" title="Link to this definition">¶</a></dt> <dd><p>alias of <a class="reference internal" href="#flask.sessions.SecureCookieSession" title="flask.sessions.SecureCookieSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecureCookieSession</span></code></a></p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.open_session"> <span class="sig-name descname"><span class="pre">open_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">request</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.open_session" title="Link to this definition">¶</a></dt> <dd><p>This is called at the beginning of each request, after pushing the request context, before matching the URL.</p> <p>This must return an object which implements a dictionary-like interface as well as the <a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><code class="xref py py-class docutils literal notranslate"><span class="pre">SessionMixin</span></code></a> interface.</p> <p>This will return <code class="docutils literal notranslate"><span class="pre">None</span></code> to indicate that loading failed in some way that is not immediately an error. The request context will fall back to using <code class="xref py py-meth docutils literal notranslate"><span class="pre">make_null_session()</span></code> in this case.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>request</strong> (<a class="reference internal" href="#flask.Request" title="flask.Request"><em>Request</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.sessions.SecureCookieSession" title="flask.sessions.SecureCookieSession">SecureCookieSession</a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSessionInterface.save_session"> <span class="sig-name descname"><span class="pre">save_session</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">session</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">response</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSessionInterface.save_session" title="Link to this definition">¶</a></dt> <dd><p>This is called at the end of each request, after generating a response, before removing the request context. It is skipped if <code class="xref py py-meth docutils literal notranslate"><span class="pre">is_null_session()</span></code> returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>session</strong> (<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a>)</p></li> <li><p><strong>response</strong> (<a class="reference internal" href="#flask.Response" title="flask.Response"><em>Response</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSession"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.sessions.</span></span><span class="sig-name descname"><span class="pre">SecureCookieSession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">initial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSession" title="Link to this definition">¶</a></dt> <dd><p>Base class for sessions based on signed cookies.</p> <p>This session backend will set the <a class="reference internal" href="#flask.sessions.SecureCookieSession.modified" title="flask.sessions.SecureCookieSession.modified"><code class="xref py py-attr docutils literal notranslate"><span class="pre">modified</span></code></a> and <a class="reference internal" href="#flask.sessions.SecureCookieSession.accessed" title="flask.sessions.SecureCookieSession.accessed"><code class="xref py py-attr docutils literal notranslate"><span class="pre">accessed</span></code></a> attributes. It cannot reliably track whether a session is new (vs. empty), so <code class="xref py py-attr docutils literal notranslate"><span class="pre">new</span></code> remains hard coded to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>initial</strong> (<em>c.Mapping</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>] </em><em>| </em><em>c.Iterable</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)"><em>tuple</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>]</em><em>] </em><em>| </em><em>None</em>)</p> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSession.modified"> <span class="sig-name descname"><span class="pre">modified</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">False</span></em><a class="headerlink" href="#flask.sessions.SecureCookieSession.modified" title="Link to this definition">¶</a></dt> <dd><p>When data is changed, this is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>. Only the session dictionary itself is tracked; if the session contains mutable data (for example a nested dict) then this must be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> manually when modifying that data. The session cookie will only be written to the response if this is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSession.accessed"> <span class="sig-name descname"><span class="pre">accessed</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">False</span></em><a class="headerlink" href="#flask.sessions.SecureCookieSession.accessed" title="Link to this definition">¶</a></dt> <dd><p>header, which allows caching proxies to cache different pages for different users.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSession.get"> <span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSession.get" title="Link to this definition">¶</a></dt> <dd><p>Return the value for key if key is in the dictionary, else default.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>key</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>default</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.SecureCookieSession.setdefault"> <span class="sig-name descname"><span class="pre">setdefault</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.SecureCookieSession.setdefault" title="Link to this definition">¶</a></dt> <dd><p>Insert key with a value of default if key is not in the dictionary.</p> <p>Return the value for key if key is in the dictionary, else default.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>key</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>default</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.sessions.NullSession"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.sessions.</span></span><span class="sig-name descname"><span class="pre">NullSession</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">initial</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession" title="Link to this definition">¶</a></dt> <dd><p>Class used to generate nicer error messages if sessions are not available. Will still allow read-only access to the empty session but fail on setting.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>initial</strong> (<em>c.Mapping</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>] </em><em>| </em><em>c.Iterable</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)"><em>tuple</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>]</em><em>] </em><em>| </em><em>None</em>)</p> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.NullSession.clear"> <span class="sig-name descname"><span class="pre">clear</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None.</span>&#160; <span class="pre">Remove</span> <span class="pre">all</span> <span class="pre">items</span> <span class="pre">from</span> <span class="pre">D.</span></span></span><a class="headerlink" href="#flask.sessions.NullSession.clear" title="Link to this definition">¶</a></dt> <dd><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.NullSession.pop"> <span class="sig-name descname"><span class="pre">pop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">k</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">d</span></span></em><span class="optional">]</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">v,</span> <span class="pre">remove</span> <span class="pre">specified</span> <span class="pre">key</span> <span class="pre">and</span> <span class="pre">return</span> <span class="pre">the</span> <span class="pre">corresponding</span> <span class="pre">value.</span></span></span><a class="headerlink" href="#flask.sessions.NullSession.pop" title="Link to this definition">¶</a></dt> <dd><p>If the key is not found, return the default if given; otherwise, raise a KeyError.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.NullSession.popitem"> <span class="sig-name descname"><span class="pre">popitem</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.popitem" title="Link to this definition">¶</a></dt> <dd><p>Remove and return a (key, value) pair as a 2-tuple.</p> <p>Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.NullSession.update"> <span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">E</span></span></em>, <span class="optional">]</span><em class="sig-param"><span class="n"><span class="pre">**F</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None.</span>&#160; <span class="pre">Update</span> <span class="pre">D</span> <span class="pre">from</span> <span class="pre">dict/iterable</span> <span class="pre">E</span> <span class="pre">and</span> <span class="pre">F.</span></span></span><a class="headerlink" href="#flask.sessions.NullSession.update" title="Link to this definition">¶</a></dt> <dd><p>If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.sessions.NullSession.setdefault"> <span class="sig-name descname"><span class="pre">setdefault</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.sessions.NullSession.setdefault" title="Link to this definition">¶</a></dt> <dd><p>Insert key with a value of default if key is not in the dictionary.</p> <p>Return the value for key if key is in the dictionary, else default.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.sessions.SessionMixin"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.sessions.</span></span><span class="sig-name descname"><span class="pre">SessionMixin</span></span><a class="headerlink" href="#flask.sessions.SessionMixin" title="Link to this definition">¶</a></dt> <dd><p>Expands a basic dictionary with session attributes.</p> <dl class="py property"> <dt class="sig sig-object py" id="flask.sessions.SessionMixin.permanent"> <em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">permanent</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a></em><a class="headerlink" href="#flask.sessions.SessionMixin.permanent" title="Link to this definition">¶</a></dt> <dd><p>This reflects the <code class="docutils literal notranslate"><span class="pre">'_permanent'</span></code> key in the dict.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SessionMixin.modified"> <span class="sig-name descname"><span class="pre">modified</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.sessions.SessionMixin.modified" title="Link to this definition">¶</a></dt> <dd><p>Some implementations can detect changes to the session and set this when that happens. The mixin default is hard coded to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.sessions.SessionMixin.accessed"> <span class="sig-name descname"><span class="pre">accessed</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.sessions.SessionMixin.accessed" title="Link to this definition">¶</a></dt> <dd><p>Some implementations can detect when session data is read or written and set this when that happens. The mixin default is hard coded to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </dd></dl> </dd></dl> <div class="admonition-notice admonition"> <p class="admonition-title">Notice</p> <p>The <a class="reference internal" href="../config/#PERMANENT_SESSION_LIFETIME" title="PERMANENT_SESSION_LIFETIME"><code class="xref py py-data docutils literal notranslate"><span class="pre">PERMANENT_SESSION_LIFETIME</span></code></a> config can be an integer or <code class="docutils literal notranslate"><span class="pre">timedelta</span></code>. The <a class="reference internal" href="#flask.Flask.permanent_session_lifetime" title="flask.Flask.permanent_session_lifetime"><code class="xref py py-attr docutils literal notranslate"><span class="pre">permanent_session_lifetime</span></code></a> attribute is always a <code class="docutils literal notranslate"><span class="pre">timedelta</span></code>.</p> </div> </section> <section id="test-client"> <h2>Test Client<a class="headerlink" href="#test-client" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.testing.FlaskClient"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.testing.</span></span><span class="sig-name descname"><span class="pre">FlaskClient</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.testing.FlaskClient" title="Link to this definition">¶</a></dt> <dd><p>Works like a regular Werkzeug test client but has knowledge about Flask’s contexts to defer the cleanup of the request context until the end of a <code class="docutils literal notranslate"><span class="pre">with</span></code> block. For general information about how to use this class refer to <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/test/#werkzeug.test.Client" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.test.Client</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.12: </span><code class="code docutils literal notranslate"><span class="pre">app.test_client()</span></code> includes preset default environment, which can be set after instantiation of the <code class="code docutils literal notranslate"><span class="pre">app.test_client()</span></code> object in <code class="code docutils literal notranslate"><span class="pre">client.environ_base</span></code>.</p> </div> </details><p>Basic usage is outlined in the <a class="reference internal" href="../testing/"><span class="doc">Testing Flask Applications</span></a> chapter.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<em>t.Any</em>)</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>)</p></li> </ul> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.testing.FlaskClient.session_transaction"> <span class="sig-name descname"><span class="pre">session_transaction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.testing.FlaskClient.session_transaction" title="Link to this definition">¶</a></dt> <dd><p>When used in combination with a <code class="docutils literal notranslate"><span class="pre">with</span></code> statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the <code class="docutils literal notranslate"><span class="pre">with</span></code> block is left the session is stored back.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">client</span><span class="o">.</span><span class="n">session_transaction</span><span class="p">()</span> <span class="k">as</span> <span class="n">session</span><span class="p">:</span> <span class="n">session</span><span class="p">[</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">42</span> </pre></div> </div> <p>Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as <a class="reference internal" href="#flask.Flask.test_request_context" title="flask.Flask.test_request_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_request_context()</span></code></a> which are directly passed through.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><em>Iterator</em></a>[<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.testing.FlaskClient.open"> <span class="sig-name descname"><span class="pre">open</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffered</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">follow_redirects</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.testing.FlaskClient.open" title="Link to this definition">¶</a></dt> <dd><p>Generate an environ dict from the given arguments, make a request to the application using it, and return the response.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<em>t.Any</em>) – Passed to <code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code> to create the environ for the request. If a single arg is passed, it can be an existing <code class="xref py py-class docutils literal notranslate"><span class="pre">EnvironBuilder</span></code> or an environ dict.</p></li> <li><p><strong>buffered</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Convert the iterator returned by the app into a list. If the iterator has a <code class="docutils literal notranslate"><span class="pre">close()</span></code> method, it is called automatically.</p></li> <li><p><strong>follow_redirects</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Make additional requests to follow HTTP redirects until a non-redirect status is returned. <code class="xref py py-attr docutils literal notranslate"><span class="pre">TestResponse.history</span></code> lists the intermediate responses.</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>TestResponse</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.1: </span>Removed the <code class="docutils literal notranslate"><span class="pre">as_tuple</span></code> parameter.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The request input stream is closed when calling <code class="docutils literal notranslate"><span class="pre">response.close()</span></code>. Input streams for redirects are automatically closed.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.5: </span>If a dict is provided as file in the dict for the <code class="docutils literal notranslate"><span class="pre">data</span></code> parameter the content type has to be called <code class="docutils literal notranslate"><span class="pre">content_type</span></code> instead of <code class="docutils literal notranslate"><span class="pre">mimetype</span></code>. This change was made for consistency with <code class="xref py py-class docutils literal notranslate"><span class="pre">werkzeug.FileWrapper</span></code>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.5: </span>Added the <code class="docutils literal notranslate"><span class="pre">follow_redirects</span></code> parameter.</p> </div> </details></dd></dl> </dd></dl> </section> <section id="test-cli-runner"> <h2>Test CLI Runner<a class="headerlink" href="#test-cli-runner" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.testing.FlaskCliRunner"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.testing.</span></span><span class="sig-name descname"><span class="pre">FlaskCliRunner</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.testing.FlaskCliRunner" title="Link to this definition">¶</a></dt> <dd><p>A <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.testing.CliRunner" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">CliRunner</span></code></a> for testing a Flask app’s CLI commands. Typically created using <a class="reference internal" href="#flask.Flask.test_cli_runner" title="flask.Flask.test_cli_runner"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_cli_runner()</span></code></a>. See <a class="reference internal" href="../testing/#testing-cli"><span class="std std-ref">Running Commands with the CLI Runner</span></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>)</p></li> </ul> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.testing.FlaskCliRunner.invoke"> <span class="sig-name descname"><span class="pre">invoke</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cli</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.testing.FlaskCliRunner.invoke" title="Link to this definition">¶</a></dt> <dd><p>Invokes a CLI command in an isolated environment. See <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.testing.CliRunner.invoke" title="(in Click v8.1.x)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">CliRunner.invoke</span></code></a> for full method documentation. See <a class="reference internal" href="../testing/#testing-cli"><span class="std std-ref">Running Commands with the CLI Runner</span></a> for examples.</p> <p>If the <code class="docutils literal notranslate"><span class="pre">obj</span></code> argument is not given, passes an instance of <a class="reference internal" href="#flask.cli.ScriptInfo" title="flask.cli.ScriptInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScriptInfo</span></code></a> that knows how to load the Flask app being tested.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>cli</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Command object to invoke. Default is the app’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">cli</span></code> group.</p></li> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – List of strings to invoke the command with.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p>a <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.testing.Result" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Result</span></code></a> object.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.testing.Result" title="(in Click v8.1.x)"><em>Result</em></a></p> </dd> </dl> </dd></dl> </dd></dl> </section> <section id="application-globals"> <h2>Application Globals<a class="headerlink" href="#application-globals" title="Link to this heading">¶</a></h2> <p>To share data that is valid for one request only from one function to another, a global variable is not good enough because it would break in threaded environments. Flask provides you with a special object that ensures it is only valid for the active request and that will return different values for each request. In a nutshell: it does the right thing, like it does for <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-class docutils literal notranslate"><span class="pre">request</span></code></a> and <a class="reference internal" href="#flask.session" title="flask.session"><code class="xref py py-class docutils literal notranslate"><span class="pre">session</span></code></a>.</p> <dl class="py data"> <dt class="sig sig-object py" id="flask.g"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">g</span></span><a class="headerlink" href="#flask.g" title="Link to this definition">¶</a></dt> <dd><p>A namespace object that can store data during an <a class="reference internal" href="../appcontext/"><span class="doc">application context</span></a>. This is an instance of <a class="reference internal" href="#flask.Flask.app_ctx_globals_class" title="flask.Flask.app_ctx_globals_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Flask.app_ctx_globals_class</span></code></a>, which defaults to <a class="reference internal" href="#flask.ctx._AppCtxGlobals" title="flask.ctx._AppCtxGlobals"><code class="xref py py-class docutils literal notranslate"><span class="pre">ctx._AppCtxGlobals</span></code></a>.</p> <p>This is a good place to store resources during a request. For example, a <code class="docutils literal notranslate"><span class="pre">before_request</span></code> function could load a user object from a session id, then set <code class="docutils literal notranslate"><span class="pre">g.user</span></code> to be used in the view function.</p> <p>This is a proxy. See <a class="reference internal" href="../reqcontext/#notes-on-proxies"><span class="std std-ref">Notes On Proxies</span></a> for more information.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.10: </span>Bound to the application context instead of the request context.</p> </div> </details></dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.ctx._AppCtxGlobals"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.ctx.</span></span><span class="sig-name descname"><span class="pre">_AppCtxGlobals</span></span><a class="headerlink" href="#flask.ctx._AppCtxGlobals" title="Link to this definition">¶</a></dt> <dd><p>A plain object. Used as a namespace for storing data during an application context.</p> <p>Creating an app context automatically creates this object, which is made available as the <code class="xref py py-data docutils literal notranslate"><span class="pre">g</span></code> proxy.</p> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname"><span class="pre">'key'</span> <span class="pre">in</span> <span class="pre">g</span></span></dt> <dd><p>Check whether an attribute is present.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="describe"> <dt class="sig sig-object"> <span class="sig-name descname"><span class="pre">iter(g)</span></span></dt> <dd><p>Return an iterator over the attribute names.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx._AppCtxGlobals.get"> <span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx._AppCtxGlobals.get" title="Link to this definition">¶</a></dt> <dd><p>Get an attribute by name, or a default value. Like <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict.get" title="(in Python v3.13)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.get()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Name of attribute to get.</p></li> <li><p><strong>default</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em> | </em><em>None</em>) – Value to return if the attribute is not present.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx._AppCtxGlobals.pop"> <span class="sig-name descname"><span class="pre">pop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx._AppCtxGlobals.pop" title="Link to this definition">¶</a></dt> <dd><p>Get and remove an attribute by name. Like <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict.pop" title="(in Python v3.13)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.pop()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Name of attribute to pop.</p></li> <li><p><strong>default</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Value to return if the attribute is not present, instead of raising a <code class="docutils literal notranslate"><span class="pre">KeyError</span></code>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx._AppCtxGlobals.setdefault"> <span class="sig-name descname"><span class="pre">setdefault</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx._AppCtxGlobals.setdefault" title="Link to this definition">¶</a></dt> <dd><p>Get the value of an attribute if it is present, otherwise set and return a default value. Like <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict.setdefault" title="(in Python v3.13)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.setdefault()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Name of attribute to get.</p></li> <li><p><strong>default</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Value to set and return if the attribute is not present.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details></dd></dl> </dd></dl> </section> <section id="useful-functions-and-classes"> <h2>Useful Functions and Classes<a class="headerlink" href="#useful-functions-and-classes" title="Link to this heading">¶</a></h2> <dl class="py data"> <dt class="sig sig-object py" id="flask.current_app"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">current_app</span></span><a class="headerlink" href="#flask.current_app" title="Link to this definition">¶</a></dt> <dd><p>A proxy to the application handling the current request. This is useful to access the application without needing to import it, or if it can’t be imported, such as when using the application factory pattern or in blueprints and extensions.</p> <p>This is only available when an <a class="reference internal" href="../appcontext/"><span class="doc">application context</span></a> is pushed. This happens automatically during requests and CLI commands. It can be controlled manually with <a class="reference internal" href="#flask.Flask.app_context" title="flask.Flask.app_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app_context()</span></code></a>.</p> <p>This is a proxy. See <a class="reference internal" href="../reqcontext/#notes-on-proxies"><span class="std std-ref">Notes On Proxies</span></a> for more information.</p> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.has_request_context"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">has_request_context</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.has_request_context" title="Link to this definition">¶</a></dt> <dd><p>If you have code that wants to test if a request context is there or not this function can be used. For instance, you may want to take advantage of request information if the request object is available, but fail silently if it is unavailable.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">remote_addr</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span> <span class="k">if</span> <span class="n">remote_addr</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">has_request_context</span><span class="p">():</span> <span class="n">remote_addr</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_addr</span> <span class="o">=</span> <span class="n">remote_addr</span> </pre></div> </div> <p>Alternatively you can also just test any of the context bound objects (such as <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-class docutils literal notranslate"><span class="pre">request</span></code></a> or <a class="reference internal" href="#flask.g" title="flask.g"><code class="xref py py-class docutils literal notranslate"><span class="pre">g</span></code></a>) for truthness:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">User</span><span class="p">(</span><span class="n">db</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">remote_addr</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">username</span> <span class="o">=</span> <span class="n">username</span> <span class="k">if</span> <span class="n">remote_addr</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">request</span><span class="p">:</span> <span class="n">remote_addr</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">remote_addr</span> <span class="bp">self</span><span class="o">.</span><span class="n">remote_addr</span> <span class="o">=</span> <span class="n">remote_addr</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.copy_current_request_context"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">copy_current_request_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.copy_current_request_context" title="Link to this definition">¶</a></dt> <dd><p>A helper function that decorates a function to retain the current request context. This is useful when working with greenlets. The moment the function is decorated a copy of the request context is created and then pushed when the function is called. The current session is also included in the copied request context.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gevent</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">copy_current_request_context</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="nd">@copy_current_request_context</span> <span class="k">def</span> <span class="nf">do_some_work</span><span class="p">():</span> <span class="c1"># do some work here, it can access flask.request or</span> <span class="c1"># flask.session like you would otherwise in the view function.</span> <span class="o">...</span> <span class="n">gevent</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="n">do_some_work</span><span class="p">)</span> <span class="k">return</span> <span class="s1">&#39;Regular response&#39;</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>F</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>F</em></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.has_app_context"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">has_app_context</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.has_app_context" title="Link to this definition">¶</a></dt> <dd><p>Works like <a class="reference internal" href="#flask.has_request_context" title="flask.has_request_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">has_request_context()</span></code></a> but for the application context. You can also just do a boolean check on the <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> object instead.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.url_for"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">url_for</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">endpoint</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_anchor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_scheme</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">_external</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">values</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.url_for" title="Link to this definition">¶</a></dt> <dd><p>Generate a URL to the given endpoint with the given values.</p> <p>This requires an active request or application context, and calls <a class="reference internal" href="#flask.Flask.url_for" title="flask.Flask.url_for"><code class="xref py py-meth docutils literal notranslate"><span class="pre">current_app.url_for()</span></code></a>. See that method for full documentation.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The endpoint name associated with the URL to generate. If this starts with a <code class="docutils literal notranslate"><span class="pre">.</span></code>, the current blueprint name (if any) will be used.</p></li> <li><p><strong>_anchor</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, append this as <code class="docutils literal notranslate"><span class="pre">#anchor</span></code> to the URL.</p></li> <li><p><strong>_method</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, generate the URL associated with this method for the endpoint.</p></li> <li><p><strong>_scheme</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – If given, the URL will have this scheme if it is external.</p></li> <li><p><strong>_external</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><em>None</em>) – If given, prefer the URL to be internal (False) or require it to be external (True). External URLs include the scheme and domain. When not in an active request, URLs are external by default.</p></li> <li><p><strong>values</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Values to use for the variable parts of the URL rule. Unknown keys are appended as query string arguments, like <code class="docutils literal notranslate"><span class="pre">?a=b&amp;c=d</span></code>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.url_for</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.10: </span>The <code class="docutils literal notranslate"><span class="pre">_scheme</span></code> parameter was added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>The <code class="docutils literal notranslate"><span class="pre">_anchor</span></code> and <code class="docutils literal notranslate"><span class="pre">_method</span></code> parameters were added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>Calls <code class="docutils literal notranslate"><span class="pre">app.handle_url_build_error</span></code> on build errors.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.abort"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">abort</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.abort" title="Link to this definition">¶</a></dt> <dd><p>Raise an <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.HTTPException" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPException</span></code></a> for the given status code.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will call its <a class="reference internal" href="#flask.Flask.aborter" title="flask.Flask.aborter"><code class="xref py py-attr docutils literal notranslate"><span class="pre">aborter</span></code></a> object, otherwise it will use <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.abort" title="(in Werkzeug v3.1.x)"><code class="xref py py-func docutils literal notranslate"><span class="pre">werkzeug.exceptions.abort()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>code</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Response" title="(in Werkzeug v3.1.x)"><em>Response</em></a>) – The status code for the exception, which must be registered in <code class="docutils literal notranslate"><span class="pre">app.aborter</span></code>.</p></li> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Passed to the exception.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Passed to the exception.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.NoReturn" title="(in Python v3.13)"><em>NoReturn</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.aborter</span></code> if available instead of always using Werkzeug’s default <code class="docutils literal notranslate"><span class="pre">abort</span></code>.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.redirect"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">redirect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">location</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">code</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">302</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Response</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.redirect" title="Link to this definition">¶</a></dt> <dd><p>Create a redirect response object.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will use its <a class="reference internal" href="#flask.Flask.redirect" title="flask.Flask.redirect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">redirect()</span></code></a> method, otherwise it will use <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.utils.redirect" title="(in Werkzeug v3.1.x)"><code class="xref py py-func docutils literal notranslate"><span class="pre">werkzeug.utils.redirect()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>location</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The URL to redirect to.</p></li> <li><p><strong>code</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a>) – The status code for the redirect.</p></li> <li><p><strong>Response</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Response" title="(in Werkzeug v3.1.x)"><em>Response</em></a><em>] </em><em>| </em><em>None</em>) – The response class to use. Not used when <code class="docutils literal notranslate"><span class="pre">current_app</span></code> is active, which uses <code class="docutils literal notranslate"><span class="pre">app.response_class</span></code>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/wrappers/#werkzeug.wrappers.Response" title="(in Werkzeug v3.1.x)"><em>Response</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.redirect</span></code> if available instead of always using Werkzeug’s default <code class="docutils literal notranslate"><span class="pre">redirect</span></code>.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.make_response"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">make_response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.make_response" title="Link to this definition">¶</a></dt> <dd><p>Sometimes it is necessary to set additional headers in a view. Because views do not have to return response objects but can return a value that is converted into a response object by Flask itself, it becomes tricky to add headers to it. This function can be called instead of using a return and you will get a response object which you can use to attach headers.</p> <p>If view looked like this and you want to add a new header:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span> </pre></div> </div> <p>You can now do something like this:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;index.html&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">))</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Parachutes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;parachutes are cool&#39;</span> <span class="k">return</span> <span class="n">response</span> </pre></div> </div> <p>This function accepts the very same arguments you can return from a view function. This for example creates a response with a 404 error code:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">render_template</span><span class="p">(</span><span class="s1">&#39;not_found.html&#39;</span><span class="p">),</span> <span class="mi">404</span><span class="p">)</span> </pre></div> </div> <p>The other use case of this function is to force the return value of a view function into a response which is helpful with view decorators:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">response</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">view_function</span><span class="p">())</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Parachutes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;parachutes are cool&#39;</span> </pre></div> </div> <p>Internally this function does the following things:</p> <ul class="simple"> <li><p>if no arguments are passed, it creates a new response argument</p></li> <li><p>if one argument is passed, <a class="reference internal" href="#flask.Flask.make_response" title="flask.Flask.make_response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flask.Flask.make_response()</span></code></a> is invoked with it.</p></li> <li><p>if more than one argument is passed, the arguments are passed to the <a class="reference internal" href="#flask.Flask.make_response" title="flask.Flask.make_response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flask.Flask.make_response()</span></code></a> function as tuple.</p></li> </ul> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.6.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>args</strong> (<em>t.Any</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.after_this_request"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">after_this_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.after_this_request" title="Link to this definition">¶</a></dt> <dd><p>Executes a function after this request. This is useful to modify response objects. The function is passed the response object and has to return the same or a new one.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="nd">@after_this_request</span> <span class="k">def</span> <span class="nf">add_header</span><span class="p">(</span><span class="n">response</span><span class="p">):</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;X-Foo&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;Parachute&#39;</span> <span class="k">return</span> <span class="n">response</span> <span class="k">return</span> <span class="s1">&#39;Hello World!&#39;</span> </pre></div> </div> <p>This is more useful if a function other than the view function wants to modify a response. For instance think of a decorator that wants to add some headers without converting the return value into a response object.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Awaitable" title="(in Python v3.13)"><em>Awaitable</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>] | <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Awaitable" title="(in Python v3.13)"><em>Awaitable</em></a>[<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]]</p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.send_file"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">send_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path_or_file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mimetype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">as_attachment</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">download_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">conditional</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">etag</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">last_modified</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_age</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.send_file" title="Link to this definition">¶</a></dt> <dd><p>Send the contents of a file to the client.</p> <p>The first argument can be a file path or a file-like object. Paths are preferred in most cases because Werkzeug can manage the file and get extra information from the path. Passing a file-like object requires that the file is opened in binary mode, and is mostly useful when building a file in memory with <a class="reference external" href="https://docs.python.org/3/library/io.html#io.BytesIO" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BytesIO</span></code></a>.</p> <p>Never pass file paths provided by a user. The path is assumed to be trusted, so a user could craft a path to access a file you didn’t intend. Use <a class="reference internal" href="#flask.send_from_directory" title="flask.send_from_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_from_directory()</span></code></a> to safely serve user-requested paths from within a directory.</p> <p>If the WSGI server sets a <code class="docutils literal notranslate"><span class="pre">file_wrapper</span></code> in <code class="docutils literal notranslate"><span class="pre">environ</span></code>, it is used, otherwise Werkzeug’s built-in wrapper is used. Alternatively, if the HTTP server supports <code class="docutils literal notranslate"><span class="pre">X-Sendfile</span></code>, configuring Flask with <code class="docutils literal notranslate"><span class="pre">USE_X_SENDFILE</span> <span class="pre">=</span> <span class="pre">True</span></code> will tell the server to send the given path, which is much more efficient than reading it in Python.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>path_or_file</strong> (<a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><em>t.AnyStr</em><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>t.BinaryIO</em>) – The path to the file to send, relative to the current working directory if a relative path is given. Alternatively, a file-like object opened in binary mode. Make sure the file pointer is seeked to the start of the data.</p></li> <li><p><strong>mimetype</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – The MIME type to send for the file. If not provided, it will try to detect it from the file name.</p></li> <li><p><strong>as_attachment</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Indicate to a browser that it should offer to save the file instead of displaying it.</p></li> <li><p><strong>download_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – The default name browsers will use when saving the file. Defaults to the passed file name.</p></li> <li><p><strong>conditional</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Enable conditional and range responses based on request headers. Requires passing a file path and <code class="docutils literal notranslate"><span class="pre">environ</span></code>.</p></li> <li><p><strong>etag</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Calculate an ETag for the file, which requires passing a file path. Can also be a string to use instead.</p></li> <li><p><strong>last_modified</strong> (<em>datetime</em><em> | </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.13)"><em>float</em></a><em> | </em><em>None</em>) – The last modified time to send for the file, in seconds. If not provided, it will try to detect it from the file path.</p></li> <li><p><strong>max_age</strong> (<em>None</em><em> | </em><em>(</em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>t.Callable</em><em>[</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>None</em><em>]</em><em>)</em>) – How long the client should cache the file, in seconds. If set, <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> will be <code class="docutils literal notranslate"><span class="pre">public</span></code>, otherwise it will be <code class="docutils literal notranslate"><span class="pre">no-cache</span></code> to prefer conditional caching.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">download_name</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">attachment_filename</span></code> parameter. If <code class="docutils literal notranslate"><span class="pre">as_attachment=False</span></code>, it is passed with <code class="docutils literal notranslate"><span class="pre">Content-Disposition:</span> <span class="pre">inline</span></code> instead.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">max_age</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">cache_timeout</span></code> parameter. <code class="docutils literal notranslate"><span class="pre">conditional</span></code> is enabled and <code class="docutils literal notranslate"><span class="pre">max_age</span></code> is not set by default.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">etag</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">add_etags</span></code> parameter. It can be a string to use instead of generating one.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>Passing a file-like object that inherits from <a class="reference external" href="https://docs.python.org/3/library/io.html#io.TextIOBase" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextIOBase</span></code></a> will raise a <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(in Python v3.13)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> rather than sending an empty file.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0: </span>Moved the implementation to Werkzeug. This is now a wrapper to pass some Flask-specific arguments.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1: </span><code class="docutils literal notranslate"><span class="pre">filename</span></code> may be a <a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">PathLike</span></code></a> object.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1: </span>Passing a <a class="reference external" href="https://docs.python.org/3/library/io.html#io.BytesIO" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">BytesIO</span></code></a> object supports range requests.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0.3: </span>Filenames are encoded with ASCII instead of Latin-1 for broader compatibility with WSGI servers.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>UTF-8 filenames as specified in <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2231.html"><strong>RFC 2231</strong></a> are supported.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.12: </span>The filename is no longer automatically inferred from file objects. If you want to use automatic MIME and etag support, pass a filename via <code class="docutils literal notranslate"><span class="pre">filename_or_fp</span></code> or <code class="docutils literal notranslate"><span class="pre">attachment_filename</span></code>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.12: </span><code class="docutils literal notranslate"><span class="pre">attachment_filename</span></code> is preferred over <code class="docutils literal notranslate"><span class="pre">filename</span></code> for MIME detection.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span><code class="docutils literal notranslate"><span class="pre">cache_timeout</span></code> defaults to <a class="reference internal" href="#flask.Flask.get_send_file_max_age" title="flask.Flask.get_send_file_max_age"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Flask.get_send_file_max_age()</span></code></a>.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.7: </span>MIME guessing and etag support for file-like objects was removed because it was unreliable. Pass a filename if you are able to, otherwise attach an etag yourself.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.5: </span>The <code class="docutils literal notranslate"><span class="pre">add_etags</span></code>, <code class="docutils literal notranslate"><span class="pre">cache_timeout</span></code> and <code class="docutils literal notranslate"><span class="pre">conditional</span></code> parameters were added. The default behavior is to add etags.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.2.</span></p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.send_from_directory"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">send_from_directory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">directory</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.send_from_directory" title="Link to this definition">¶</a></dt> <dd><p>Send a file from within a directory using <a class="reference internal" href="#flask.send_file" title="flask.send_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_file()</span></code></a>.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/uploads/&lt;path:name&gt;&quot;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">download_file</span><span class="p">(</span><span class="n">name</span><span class="p">):</span> <span class="k">return</span> <span class="n">send_from_directory</span><span class="p">(</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;UPLOAD_FOLDER&#39;</span><span class="p">],</span> <span class="n">name</span><span class="p">,</span> <span class="n">as_attachment</span><span class="o">=</span><span class="kc">True</span> <span class="p">)</span> </pre></div> </div> <p>This is a secure way to serve files from a folder, such as static files or uploads. Uses <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/utils/#werkzeug.security.safe_join" title="(in Werkzeug v3.1.x)"><code class="xref py py-func docutils literal notranslate"><span class="pre">safe_join()</span></code></a> to ensure the path coming from the client is not maliciously crafted to point outside the specified directory.</p> <p>If the final path does not point to an existing regular file, raises a 404 <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.NotFound" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotFound</span></code></a> error.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>directory</strong> (<a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The directory that <code class="docutils literal notranslate"><span class="pre">path</span></code> must be located under, relative to the current application’s root path. This <em>must not</em> be a value provided by the client, otherwise it becomes insecure.</p></li> <li><p><strong>path</strong> (<a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The path to the file to send, relative to <code class="docutils literal notranslate"><span class="pre">directory</span></code>.</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>) – Arguments to pass to <a class="reference internal" href="#flask.send_file" title="flask.send_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">send_file()</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">path</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">filename</span></code> parameter.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0: </span>Moved the implementation to Werkzeug. This is now a wrapper to pass some Flask-specific arguments.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.5.</span></p> </div> </details></dd></dl> </section> <section id="message-flashing"> <h2>Message Flashing<a class="headerlink" href="#message-flashing" title="Link to this heading">¶</a></h2> <dl class="py function"> <dt class="sig sig-object py" id="flask.flash"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">flash</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">category</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'message'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.flash" title="Link to this definition">¶</a></dt> <dd><p>Flashes a message to the next request. In order to remove the flashed message from the session and to display it to the user, the template has to call <a class="reference internal" href="#flask.get_flashed_messages" title="flask.get_flashed_messages"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_flashed_messages()</span></code></a>.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.3: </span><code class="code docutils literal notranslate"><span class="pre">category</span></code> parameter added.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>message</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the message to be flashed.</p></li> <li><p><strong>category</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the category for the message. The following values are recommended: <code class="docutils literal notranslate"><span class="pre">'message'</span></code> for any kind of message, <code class="docutils literal notranslate"><span class="pre">'error'</span></code> for errors, <code class="docutils literal notranslate"><span class="pre">'info'</span></code> for information messages and <code class="docutils literal notranslate"><span class="pre">'warning'</span></code> for warnings. However any kind of string can be used as category.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.get_flashed_messages"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">get_flashed_messages</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">with_categories</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">category_filter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.get_flashed_messages" title="Link to this definition">¶</a></dt> <dd><p>Pulls all flashed messages from the session and returns them. Further calls in the same request to the function will return the same messages. By default just the messages are returned, but when <code class="code docutils literal notranslate"><span class="pre">with_categories</span></code> is set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the return value will be a list of tuples in the form <code class="docutils literal notranslate"><span class="pre">(category,</span> <span class="pre">message)</span></code> instead.</p> <p>Filter the flashed messages to one or more categories by providing those categories in <code class="code docutils literal notranslate"><span class="pre">category_filter</span></code>. This allows rendering categories in separate html blocks. The <code class="code docutils literal notranslate"><span class="pre">with_categories</span></code> and <code class="code docutils literal notranslate"><span class="pre">category_filter</span></code> arguments are distinct:</p> <ul class="simple"> <li><p><code class="code docutils literal notranslate"><span class="pre">with_categories</span></code> controls whether categories are returned with message text (<code class="docutils literal notranslate"><span class="pre">True</span></code> gives a tuple, where <code class="docutils literal notranslate"><span class="pre">False</span></code> gives just the message text).</p></li> <li><p><code class="code docutils literal notranslate"><span class="pre">category_filter</span></code> filters the messages down to only those matching the provided categories.</p></li> </ul> <p>See <a class="reference internal" href="../patterns/flashing/"><span class="doc">Message Flashing</span></a> for examples.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span><code class="code docutils literal notranslate"><span class="pre">category_filter</span></code> parameter added.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.3: </span><code class="code docutils literal notranslate"><span class="pre">with_categories</span></code> parameter added.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>with_categories</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – set to <code class="docutils literal notranslate"><span class="pre">True</span></code> to also receive categories.</p></li> <li><p><strong>category_filter</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterable" title="(in Python v3.13)"><em>Iterable</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – filter of categories to limit return values. Only categories in the list will be returned.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)">list</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>] | <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)">list</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)">tuple</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]]</p> </dd> </dl> </dd></dl> </section> <section id="module-flask.json"> <span id="json-support"></span><h2>JSON Support<a class="headerlink" href="#module-flask.json" title="Link to this heading">¶</a></h2> <p>Flask uses Python’s built-in <a class="reference external" href="https://docs.python.org/3/library/json.html#module-json" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> module for handling JSON by default. The JSON implementation can be changed by assigning a different provider to <a class="reference internal" href="#flask.Flask.json_provider_class" title="flask.Flask.json_provider_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">flask.Flask.json_provider_class</span></code></a> or <a class="reference internal" href="#flask.Flask.json" title="flask.Flask.json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">flask.Flask.json</span></code></a>. The functions provided by <code class="docutils literal notranslate"><span class="pre">flask.json</span></code> will use methods on <code class="docutils literal notranslate"><span class="pre">app.json</span></code> if an app context is active.</p> <p>Jinja’s <code class="docutils literal notranslate"><span class="pre">|tojson</span></code> filter is configured to use the app’s JSON provider. The filter marks the output with <code class="docutils literal notranslate"><span class="pre">|safe</span></code>. Use it to render data inside HTML <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> tags.</p> <div class="highlight-html+jinja notranslate"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">script</span><span class="p">&gt;</span> <span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">names</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="cp">{{</span> <span class="nv">names</span><span class="o">|</span><span class="nf">tojson</span> <span class="cp">}}</span><span class="p">;</span> <span class="w"> </span><span class="nx">renderChart</span><span class="p">(</span><span class="nx">names</span><span class="p">,</span><span class="w"> </span><span class="cp">{{</span> <span class="nv">axis_data</span><span class="o">|</span><span class="nf">tojson</span> <span class="cp">}}</span><span class="p">);</span> <span class="p">&lt;/</span><span class="nt">script</span><span class="p">&gt;</span> </pre></div> </div> <dl class="py function"> <dt class="sig sig-object py" id="flask.json.jsonify"> <span class="sig-prename descclassname"><span class="pre">flask.json.</span></span><span class="sig-name descname"><span class="pre">jsonify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.jsonify" title="Link to this definition">¶</a></dt> <dd><p>Serialize the given arguments as JSON, and return a <a class="reference internal" href="#flask.Response" title="flask.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object with the <code class="docutils literal notranslate"><span class="pre">application/json</span></code> mimetype. A dict or list returned from a view will be converted to a JSON response automatically without needing to call this.</p> <p>This requires an active request or application context, and calls <a class="reference internal" href="#flask.json.provider.JSONProvider.response" title="flask.json.provider.JSONProvider.response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app.json.response()</span></code></a>.</p> <p>In debug mode, the output is formatted with indentation to make it easier to read. This may also be controlled by the provider.</p> <p>Either positional or keyword arguments can be given, not both. If no arguments are given, <code class="docutils literal notranslate"><span class="pre">None</span></code> is serialized.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<em>t.Any</em>) – A single value to serialize, or multiple values to treat as a list to serialize.</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>) – Treat as a dict to serialize.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.json.response</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.2: </span><a class="reference external" href="https://docs.python.org/3/library/decimal.html#decimal.Decimal" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> is supported by converting to a string.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.11: </span>Added support for serializing top-level arrays. This was a security risk in ancient browsers. See <a class="reference internal" href="../web-security/#security-json"><span class="std std-ref">JSON Security</span></a>.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.2.</span></p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.json.dumps"> <span class="sig-prename descclassname"><span class="pre">flask.json.</span></span><span class="sig-name descname"><span class="pre">dumps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.dumps" title="Link to this definition">¶</a></dt> <dd><p>Serialize data as JSON.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will use its <a class="reference internal" href="#flask.json.provider.JSONProvider.dumps" title="flask.json.provider.JSONProvider.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app.json.dumps()</span></code></a> method, otherwise it will use <a class="reference external" href="https://docs.python.org/3/library/json.html#json.dumps" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dumps()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The data to serialize.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Arguments passed to the <code class="docutils literal notranslate"><span class="pre">dumps</span></code> implementation.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>The <code class="docutils literal notranslate"><span class="pre">app</span></code> parameter was removed.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.json.dumps</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0.2: </span><a class="reference external" href="https://docs.python.org/3/library/decimal.html#decimal.Decimal" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> is supported by converting to a string.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">encoding</span></code> will be removed in Flask 2.1.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0.3: </span><code class="docutils literal notranslate"><span class="pre">app</span></code> can be passed directly, rather than requiring an app context for configuration.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.json.dump"> <span class="sig-prename descclassname"><span class="pre">flask.json.</span></span><span class="sig-name descname"><span class="pre">dump</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.dump" title="Link to this definition">¶</a></dt> <dd><p>Serialize data as JSON and write to a file.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will use its <a class="reference internal" href="#flask.json.provider.JSONProvider.dump" title="flask.json.provider.JSONProvider.dump"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app.json.dump()</span></code></a> method, otherwise it will use <a class="reference external" href="https://docs.python.org/3/library/json.html#json.dump" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dump()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The data to serialize.</p></li> <li><p><strong>fp</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – A file opened for writing text. Should use the UTF-8 encoding to be valid JSON.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Arguments passed to the <code class="docutils literal notranslate"><span class="pre">dump</span></code> implementation.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>The <code class="docutils literal notranslate"><span class="pre">app</span></code> parameter was removed.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.json.dump</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>Writing to a binary file, and the <code class="docutils literal notranslate"><span class="pre">encoding</span></code> argument, will be removed in Flask 2.1.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.json.loads"> <span class="sig-prename descclassname"><span class="pre">flask.json.</span></span><span class="sig-name descname"><span class="pre">loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.loads" title="Link to this definition">¶</a></dt> <dd><p>Deserialize data as JSON.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will use its <a class="reference internal" href="#flask.json.provider.JSONProvider.loads" title="flask.json.provider.JSONProvider.loads"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app.json.loads()</span></code></a> method, otherwise it will use <a class="reference external" href="https://docs.python.org/3/library/json.html#json.loads" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>s</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a>) – Text or UTF-8 bytes.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Arguments passed to the <code class="docutils literal notranslate"><span class="pre">loads</span></code> implementation.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>The <code class="docutils literal notranslate"><span class="pre">app</span></code> parameter was removed.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.json.loads</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">encoding</span></code> will be removed in Flask 2.1. The data must be a string or UTF-8 bytes.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0.3: </span><code class="docutils literal notranslate"><span class="pre">app</span></code> can be passed directly, rather than requiring an app context for configuration.</p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.json.load"> <span class="sig-prename descclassname"><span class="pre">flask.json.</span></span><span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.load" title="Link to this definition">¶</a></dt> <dd><p>Deserialize data as JSON read from a file.</p> <p>If <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> is available, it will use its <a class="reference internal" href="#flask.json.provider.JSONProvider.load" title="flask.json.provider.JSONProvider.load"><code class="xref py py-meth docutils literal notranslate"><span class="pre">app.json.load()</span></code></a> method, otherwise it will use <a class="reference external" href="https://docs.python.org/3/library/json.html#json.load" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.load()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>fp</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a>) – A file opened for reading text or UTF-8 bytes.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Arguments passed to the <code class="docutils literal notranslate"><span class="pre">load</span></code> implementation.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>The <code class="docutils literal notranslate"><span class="pre">app</span></code> parameter was removed.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Calls <code class="docutils literal notranslate"><span class="pre">current_app.json.load</span></code>, allowing an app to override the behavior.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>The <code class="docutils literal notranslate"><span class="pre">app</span></code> parameter will be removed in Flask 2.3.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span><code class="docutils literal notranslate"><span class="pre">encoding</span></code> will be removed in Flask 2.1. The file must be text mode, or binary mode with UTF-8 bytes.</p> </div> </details></dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.json.provider.</span></span><span class="sig-name descname"><span class="pre">JSONProvider</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider" title="Link to this definition">¶</a></dt> <dd><p>A standard set of JSON operations for an application. Subclasses of this can be used to customize JSON behavior or use different JSON libraries.</p> <p>To implement a provider for a specific library, subclass this base class and implement at least <a class="reference internal" href="#flask.json.provider.JSONProvider.dumps" title="flask.json.provider.JSONProvider.dumps"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dumps()</span></code></a> and <a class="reference internal" href="#flask.json.provider.JSONProvider.loads" title="flask.json.provider.JSONProvider.loads"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loads()</span></code></a>. All other methods have default implementations.</p> <p>To use a different provider, either subclass <code class="docutils literal notranslate"><span class="pre">Flask</span></code> and set <a class="reference internal" href="#flask.Flask.json_provider_class" title="flask.Flask.json_provider_class"><code class="xref py py-attr docutils literal notranslate"><span class="pre">json_provider_class</span></code></a> to a provider class, or set <a class="reference internal" href="#flask.Flask.json" title="flask.Flask.json"><code class="xref py py-attr docutils literal notranslate"><span class="pre">app.json</span></code></a> to an instance of the class.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<em>App</em>) – An application instance. This will be stored as a <code class="xref py py-class docutils literal notranslate"><span class="pre">weakref.proxy</span></code> on the <code class="xref py py-attr docutils literal notranslate"><span class="pre">_app</span></code> attribute.</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details><dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider.dumps"> <span class="sig-name descname"><span class="pre">dumps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider.dumps" title="Link to this definition">¶</a></dt> <dd><p>Serialize data as JSON.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The data to serialize.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – May be passed to the underlying JSON library.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider.dump"> <span class="sig-name descname"><span class="pre">dump</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider.dump" title="Link to this definition">¶</a></dt> <dd><p>Serialize data as JSON and write to a file.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The data to serialize.</p></li> <li><p><strong>fp</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – A file opened for writing text. Should use the UTF-8 encoding to be valid JSON.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – May be passed to the underlying JSON library.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider.loads"> <span class="sig-name descname"><span class="pre">loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider.loads" title="Link to this definition">¶</a></dt> <dd><p>Deserialize data as JSON.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>s</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a>) – Text or UTF-8 bytes.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – May be passed to the underlying JSON library.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider.load"> <span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fp</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider.load" title="Link to this definition">¶</a></dt> <dd><p>Deserialize data as JSON read from a file.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>fp</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.IO" title="(in Python v3.13)"><em>IO</em></a>) – A file opened for reading text or UTF-8 bytes.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – May be passed to the underlying JSON library.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.JSONProvider.response"> <span class="sig-name descname"><span class="pre">response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.JSONProvider.response" title="Link to this definition">¶</a></dt> <dd><p>Serialize the given arguments as JSON, and return a <a class="reference internal" href="#flask.Response" title="flask.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object with the <code class="docutils literal notranslate"><span class="pre">application/json</span></code> mimetype.</p> <p>The <a class="reference internal" href="#flask.json.jsonify" title="flask.json.jsonify"><code class="xref py py-func docutils literal notranslate"><span class="pre">jsonify()</span></code></a> function calls this method for the current application.</p> <p>Either positional or keyword arguments can be given, not both. If no arguments are given, <code class="docutils literal notranslate"><span class="pre">None</span></code> is serialized.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<em>t.Any</em>) – A single value to serialize, or multiple values to treat as a list to serialize.</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>) – Treat as a dict to serialize.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.json.provider.</span></span><span class="sig-name descname"><span class="pre">DefaultJSONProvider</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider" title="Link to this definition">¶</a></dt> <dd><p>Provide JSON operations using Python’s built-in <a class="reference external" href="https://docs.python.org/3/library/json.html#module-json" title="(in Python v3.13)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> library. Serializes the following additional data types:</p> <ul class="simple"> <li><p><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> and <a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.date" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> are serialized to <span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc822.html"><strong>RFC 822</strong></a> strings. This is the same as the HTTP date format.</p></li> <li><p><a class="reference external" href="https://docs.python.org/3/library/uuid.html#uuid.UUID" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">uuid.UUID</span></code></a> is serialized to a string.</p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">dataclasses.dataclass</span></code> is passed to <a class="reference external" href="https://docs.python.org/3/library/dataclasses.html#dataclasses.asdict" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclasses.asdict()</span></code></a>.</p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Markup</span></code> (or any object with a <code class="docutils literal notranslate"><span class="pre">__html__</span></code> method) will call the <code class="docutils literal notranslate"><span class="pre">__html__</span></code> method to get a string.</p></li> </ul> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<em>App</em>)</p> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.default"> <em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">default</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">o</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.default" title="Link to this definition">¶</a></dt> <dd><p>Apply this function to any object that <code class="xref py py-meth docutils literal notranslate"><span class="pre">json.dumps()</span></code> does not know how to serialize. It should return a valid JSON type or raise a <code class="docutils literal notranslate"><span class="pre">TypeError</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>o</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.ensure_ascii"> <span class="sig-name descname"><span class="pre">ensure_ascii</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.ensure_ascii" title="Link to this definition">¶</a></dt> <dd><p>Replace non-ASCII characters with escape sequences. This may be more compatible with some clients, but can be disabled for better performance and size.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.sort_keys"> <span class="sig-name descname"><span class="pre">sort_keys</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.sort_keys" title="Link to this definition">¶</a></dt> <dd><p>Sort the keys in any serialized dicts. This may be useful for some caching situations, but can be disabled for better performance. When enabled, keys must all be strings, they are not converted before sorting.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.compact"> <span class="sig-name descname"><span class="pre">compact</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.compact" title="Link to this definition">¶</a></dt> <dd><p>If <code class="docutils literal notranslate"><span class="pre">True</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> out of debug mode, the <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.response" title="flask.json.provider.DefaultJSONProvider.response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">response()</span></code></a> output will not add indentation, newlines, or spaces. If <code class="docutils literal notranslate"><span class="pre">False</span></code>, or <code class="docutils literal notranslate"><span class="pre">None</span></code> in debug mode, it will use a non-compact representation.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.mimetype"> <span class="sig-name descname"><span class="pre">mimetype</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">'application/json'</span></em><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.mimetype" title="Link to this definition">¶</a></dt> <dd><p>The mimetype set in <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.response" title="flask.json.provider.DefaultJSONProvider.response"><code class="xref py py-meth docutils literal notranslate"><span class="pre">response()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.dumps"> <span class="sig-name descname"><span class="pre">dumps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.dumps" title="Link to this definition">¶</a></dt> <dd><p>Serialize data as JSON to a string.</p> <p>Keyword arguments are passed to <a class="reference external" href="https://docs.python.org/3/library/json.html#json.dumps" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dumps()</span></code></a>. Sets some parameter defaults from the <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.default" title="flask.json.provider.DefaultJSONProvider.default"><code class="xref py py-attr docutils literal notranslate"><span class="pre">default</span></code></a>, <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.ensure_ascii" title="flask.json.provider.DefaultJSONProvider.ensure_ascii"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ensure_ascii</span></code></a>, and <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.sort_keys" title="flask.json.provider.DefaultJSONProvider.sort_keys"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sort_keys</span></code></a> attributes.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The data to serialize.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Passed to <a class="reference external" href="https://docs.python.org/3/library/json.html#json.dumps" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dumps()</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.loads"> <span class="sig-name descname"><span class="pre">loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.loads" title="Link to this definition">¶</a></dt> <dd><p>Deserialize data as JSON from a string or bytes.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>s</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><em>bytes</em></a>) – Text or UTF-8 bytes.</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – Passed to <a class="reference external" href="https://docs.python.org/3/library/json.html#json.loads" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.provider.DefaultJSONProvider.response"> <span class="sig-name descname"><span class="pre">response</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.provider.DefaultJSONProvider.response" title="Link to this definition">¶</a></dt> <dd><p>Serialize the given arguments as JSON, and return a <a class="reference internal" href="#flask.Response" title="flask.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> object with it. The response mimetype will be “application/json” and can be changed with <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.mimetype" title="flask.json.provider.DefaultJSONProvider.mimetype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">mimetype</span></code></a>.</p> <p>If <a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.compact" title="flask.json.provider.DefaultJSONProvider.compact"><code class="xref py py-attr docutils literal notranslate"><span class="pre">compact</span></code></a> is <code class="docutils literal notranslate"><span class="pre">False</span></code> or debug mode is enabled, the output will be formatted to be easier to read.</p> <p>Either positional or keyword arguments can be given, not both. If no arguments are given, <code class="docutils literal notranslate"><span class="pre">None</span></code> is serialized.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<em>t.Any</em>) – A single value to serialize, or multiple values to treat as a list to serialize.</p></li> <li><p><strong>kwargs</strong> (<em>t.Any</em>) – Treat as a dict to serialize.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference internal" href="#flask.Response" title="flask.Response">Response</a></p> </dd> </dl> </dd></dl> </dd></dl> <section id="tagged-json"> <span id="module-flask.json.tag"></span><h3>Tagged JSON<a class="headerlink" href="#tagged-json" title="Link to this heading">¶</a></h3> <p>A compact representation for lossless serialization of non-standard JSON types. <a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface" title="flask.sessions.SecureCookieSessionInterface"><code class="xref py py-class docutils literal notranslate"><span class="pre">SecureCookieSessionInterface</span></code></a> uses this to serialize the session data, but it may be useful in other places. It can be extended to support other types.</p> <dl class="py class"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.json.tag.</span></span><span class="sig-name descname"><span class="pre">TaggedJSONSerializer</span></span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer" title="Link to this definition">¶</a></dt> <dd><p>Serializer that uses a tag system to compactly represent objects that are not JSON types. Passed as the intermediate serializer to <code class="xref py py-class docutils literal notranslate"><span class="pre">itsdangerous.Serializer</span></code>.</p> <p>The following extra types are supported:</p> <ul class="simple"> <li><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a></p></li> <li><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a></p></li> <li><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#bytes" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a></p></li> <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">Markup</span></code></p></li> <li><p><a class="reference external" href="https://docs.python.org/3/library/uuid.html#uuid.UUID" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">UUID</span></code></a></p></li> <li><p><a class="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a></p></li> </ul> <dl class="field-list simple"> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.default_tags"> <span class="sig-name descname"><span class="pre">default_tags</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[&lt;class</span> <span class="pre">'flask.json.tag.TagDict'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.PassDict'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.TagTuple'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.PassList'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.TagBytes'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.TagMarkup'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.TagUUID'&gt;,</span> <span class="pre">&lt;class</span> <span class="pre">'flask.json.tag.TagDateTime'&gt;]</span></em><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.default_tags" title="Link to this definition">¶</a></dt> <dd><p>Tag classes to bind when creating the serializer. Other tags can be added later using <a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.register" title="flask.json.tag.TaggedJSONSerializer.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register()</span></code></a>.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.register"> <span class="sig-name descname"><span class="pre">register</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tag_class</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">index</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.register" title="Link to this definition">¶</a></dt> <dd><p>Register a new tag with this serializer.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>tag_class</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.13)"><em>type</em></a><em>[</em><a class="reference internal" href="#flask.json.tag.JSONTag" title="flask.json.tag.JSONTag"><em>JSONTag</em></a><em>]</em>) – tag class to register. Will be instantiated with this serializer instance.</p></li> <li><p><strong>force</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – overwrite an existing tag. If false (default), a <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#KeyError" title="(in Python v3.13)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> is raised.</p></li> <li><p><strong>index</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.13)"><em>int</em></a><em> | </em><em>None</em>) – index to insert the new tag in the tag order. Useful when the new tag is a special case of an existing tag. If <code class="docutils literal notranslate"><span class="pre">None</span></code> (default), the tag is appended to the end of the order.</p></li> </ul> </dd> <dt class="field-even">Raises<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#KeyError" title="(in Python v3.13)"><strong>KeyError</strong></a> – if the tag key is already registered and <code class="docutils literal notranslate"><span class="pre">force</span></code> is not true.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.tag"> <span class="sig-name descname"><span class="pre">tag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.tag" title="Link to this definition">¶</a></dt> <dd><p>Convert a value to a tagged representation if necessary.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.untag"> <span class="sig-name descname"><span class="pre">untag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.untag" title="Link to this definition">¶</a></dt> <dd><p>Convert a tagged representation back to the original type.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.dumps"> <span class="sig-name descname"><span class="pre">dumps</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.dumps" title="Link to this definition">¶</a></dt> <dd><p>Tag the value and dump it to a compact JSON string.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.TaggedJSONSerializer.loads"> <span class="sig-name descname"><span class="pre">loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.TaggedJSONSerializer.loads" title="Link to this definition">¶</a></dt> <dd><p>Load data from a JSON string and deserialized any tagged objects.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.json.tag.</span></span><span class="sig-name descname"><span class="pre">JSONTag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">serializer</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.JSONTag" title="Link to this definition">¶</a></dt> <dd><p>Base class for defining type tags for <a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer" title="flask.json.tag.TaggedJSONSerializer"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaggedJSONSerializer</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>serializer</strong> (<a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer" title="flask.json.tag.TaggedJSONSerializer"><em>TaggedJSONSerializer</em></a>)</p> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag.key"> <span class="sig-name descname"><span class="pre">key</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">''</span></em><a class="headerlink" href="#flask.json.tag.JSONTag.key" title="Link to this definition">¶</a></dt> <dd><p>The tag to mark the serialized object with. If empty, this tag is only used as an intermediate step during tagging.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag.check"> <span class="sig-name descname"><span class="pre">check</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.JSONTag.check" title="Link to this definition">¶</a></dt> <dd><p>Check if the given value should be tagged by this tag.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag.to_json"> <span class="sig-name descname"><span class="pre">to_json</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.JSONTag.to_json" title="Link to this definition">¶</a></dt> <dd><p>Convert the Python object to an object that is a valid JSON type. The tag will be added later.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag.to_python"> <span class="sig-name descname"><span class="pre">to_python</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.JSONTag.to_python" title="Link to this definition">¶</a></dt> <dd><p>Convert the JSON representation back to the correct type. The tag will already be removed.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.json.tag.JSONTag.tag"> <span class="sig-name descname"><span class="pre">tag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.json.tag.JSONTag.tag" title="Link to this definition">¶</a></dt> <dd><p>Convert the value to a valid JSON type and add the tag structure around it.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>value</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)">dict</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> </dd></dl> </dd></dl> <p>Let’s see an example that adds support for <a class="reference external" href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="(in Python v3.13)"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code></a>. Dicts don’t have an order in JSON, so to handle this we will dump the items as a list of <code class="docutils literal notranslate"><span class="pre">[key,</span> <span class="pre">value]</span></code> pairs. Subclass <a class="reference internal" href="#flask.json.tag.JSONTag" title="flask.json.tag.JSONTag"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONTag</span></code></a> and give it the new key <code class="docutils literal notranslate"><span class="pre">'</span> <span class="pre">od'</span></code> to identify the type. The session serializer processes dicts first, so insert the new tag at the front of the order since <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> must be processed before <code class="docutils literal notranslate"><span class="pre">dict</span></code>.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask.json.tag</span> <span class="kn">import</span> <span class="n">JSONTag</span> <span class="k">class</span> <span class="nc">TagOrderedDict</span><span class="p">(</span><span class="n">JSONTag</span><span class="p">):</span> <span class="vm">__slots__</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;serializer&#39;</span><span class="p">,)</span> <span class="n">key</span> <span class="o">=</span> <span class="s1">&#39; od&#39;</span> <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">OrderedDict</span><span class="p">)</span> <span class="k">def</span> <span class="nf">to_json</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="k">return</span> <span class="p">[[</span><span class="n">k</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer</span><span class="o">.</span><span class="n">tag</span><span class="p">(</span><span class="n">v</span><span class="p">)]</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">iteritems</span><span class="p">(</span><span class="n">value</span><span class="p">)]</span> <span class="k">def</span> <span class="nf">to_python</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="k">return</span> <span class="n">OrderedDict</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="n">app</span><span class="o">.</span><span class="n">session_interface</span><span class="o">.</span><span class="n">serializer</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">TagOrderedDict</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> </pre></div> </div> </section> </section> <section id="template-rendering"> <h2>Template Rendering<a class="headerlink" href="#template-rendering" title="Link to this heading">¶</a></h2> <dl class="py function"> <dt class="sig sig-object py" id="flask.render_template"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">render_template</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">template_name_or_list</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.render_template" title="Link to this definition">¶</a></dt> <dd><p>Render a template by name with the given context.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>template_name_or_list</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.Template" title="(in Jinja v3.1.x)"><em>Template</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><em>list</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.Template" title="(in Jinja v3.1.x)"><em>Template</em></a><em>]</em>) – The name of the template to render. If a list is given, the first name to exist will be rendered.</p></li> <li><p><strong>context</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The variables to make available in the template.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.render_template_string"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">render_template_string</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.render_template_string" title="Link to this definition">¶</a></dt> <dd><p>Render a template from the given source string with the given context.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>source</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The source code of the template to render.</p></li> <li><p><strong>context</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The variables to make available in the template.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.stream_template"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">stream_template</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">template_name_or_list</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.stream_template" title="Link to this definition">¶</a></dt> <dd><p>Render a template by name with the given context as a stream. This returns an iterator of strings, which can be used as a streaming response from a view.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>template_name_or_list</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.Template" title="(in Jinja v3.1.x)"><em>Template</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><em>list</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://jinja.palletsprojects.com/en/stable/api/#jinja2.Template" title="(in Jinja v3.1.x)"><em>Template</em></a><em>]</em>) – The name of the template to render. If a list is given, the first name to exist will be rendered.</p></li> <li><p><strong>context</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The variables to make available in the template.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><em>Iterator</em></a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.stream_template_string"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">stream_template_string</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">context</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.stream_template_string" title="Link to this definition">¶</a></dt> <dd><p>Render a template from the given source string with the given context as a stream. This returns an iterator of strings, which can be used as a streaming response from a view.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>source</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – The source code of the template to render.</p></li> <li><p><strong>context</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – The variables to make available in the template.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><em>Iterator</em></a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.get_template_attribute"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">get_template_attribute</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">template_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">attribute</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.get_template_attribute" title="Link to this definition">¶</a></dt> <dd><p>Loads a macro (or variable) a template exports. This can be used to invoke a macro from within Python code. If you for example have a template named <code class="file docutils literal notranslate"><span class="pre">_cider.html</span></code> with the following contents:</p> <div class="highlight-html+jinja notranslate"><div class="highlight"><pre><span></span><span class="cp">{%</span> <span class="k">macro</span> <span class="nv">hello</span><span class="o">(</span><span class="nv">name</span><span class="o">)</span> <span class="cp">%}</span>Hello <span class="cp">{{</span> <span class="nv">name</span> <span class="cp">}}</span>!<span class="cp">{%</span> <span class="k">endmacro</span> <span class="cp">%}</span> </pre></div> </div> <p>You can access this from Python code like this:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hello</span> <span class="o">=</span> <span class="n">get_template_attribute</span><span class="p">(</span><span class="s1">&#39;_cider.html&#39;</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">)</span> <span class="k">return</span> <span class="n">hello</span><span class="p">(</span><span class="s1">&#39;World&#39;</span><span class="p">)</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.2.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>template_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the name of the template</p></li> <li><p><strong>attribute</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – the name of the variable of macro to access</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> </section> <section id="configuration"> <h2>Configuration<a class="headerlink" href="#configuration" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.Config"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">Config</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">root_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">defaults</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config" title="Link to this definition">¶</a></dt> <dd><p>Works exactly like a dict but provides ways to fill it from files or special dictionaries. There are two common patterns to populate the config.</p> <p>Either you can fill the config from a config file:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_pyfile</span><span class="p">(</span><span class="s1">&#39;yourconfig.cfg&#39;</span><span class="p">)</span> </pre></div> </div> <p>Or alternatively you can define the configuration options in the module that calls <a class="reference internal" href="#flask.Config.from_object" title="flask.Config.from_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_object()</span></code></a> or provide an import path to a module that should be loaded. It is also possible to tell it to use the same module and with that provide the configuration values just before the call:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">DEBUG</span> <span class="o">=</span> <span class="kc">True</span> <span class="n">SECRET_KEY</span> <span class="o">=</span> <span class="s1">&#39;development key&#39;</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span> </pre></div> </div> <p>In both cases (loading from any Python file or loading from modules), only uppercase keys are added to the config. This makes it possible to use lowercase values in the config file for temporary values that are not added to the config or to define the config keys in the same file that implements the application.</p> <p>Probably the most interesting way to load configurations is from an environment variable pointing to a file:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_envvar</span><span class="p">(</span><span class="s1">&#39;YOURAPPLICATION_SETTINGS&#39;</span><span class="p">)</span> </pre></div> </div> <p>In this case before launching the application you have to set this environment variable to the file you want to use. On Linux and OS X use the export statement:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">export</span> <span class="n">YOURAPPLICATION_SETTINGS</span><span class="o">=</span><span class="s1">&#39;/path/to/config/file&#39;</span> </pre></div> </div> <p>On windows use <code class="code docutils literal notranslate"><span class="pre">set</span></code> instead.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>root_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>os.PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – path to which files are read relative from. When the config object is created by the application, this is the application’s <a class="reference internal" href="#flask.Flask.root_path" title="flask.Flask.root_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">root_path</span></code></a>.</p></li> <li><p><strong>defaults</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><em>dict</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><em>t.Any</em><em>] </em><em>| </em><em>None</em>) – an optional dictionary of default values</p></li> </ul> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_envvar"> <span class="sig-name descname"><span class="pre">from_envvar</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">variable_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">silent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_envvar" title="Link to this definition">¶</a></dt> <dd><p>Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_pyfile</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;YOURAPPLICATION_SETTINGS&#39;</span><span class="p">])</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>variable_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – name of the environment variable</p></li> <li><p><strong>silent</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – set to <code class="docutils literal notranslate"><span class="pre">True</span></code> if you want silent failure for missing files.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the file was loaded successfully.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_prefixed_env"> <span class="sig-name descname"><span class="pre">from_prefixed_env</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">prefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'FLASK'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">loads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">json.loads</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_prefixed_env" title="Link to this definition">¶</a></dt> <dd><p>Load any environment variables that start with <code class="docutils literal notranslate"><span class="pre">FLASK_</span></code>, dropping the prefix from the env key for the config key. Values are passed through a loading function to attempt to convert them to more specific types than strings.</p> <p>Keys are loaded in <a class="reference external" href="https://docs.python.org/3/library/functions.html#sorted" title="(in Python v3.13)"><code class="xref py py-func docutils literal notranslate"><span class="pre">sorted()</span></code></a> order.</p> <p>The default loading function attempts to parse values as any valid JSON type, including dicts and lists.</p> <p>Specific items in nested dicts can be set by separating the keys with double underscores (<code class="docutils literal notranslate"><span class="pre">__</span></code>). If an intermediate key doesn’t exist, it will be initialized to an empty dict.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>prefix</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – Load env vars that start with this prefix, separated with an underscore (<code class="docutils literal notranslate"><span class="pre">_</span></code>).</p></li> <li><p><strong>loads</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a><em>[</em><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>]</em>) – Pass each string value to this function and use the returned value as the config value. If any error is raised it is ignored and the value remains a string. The default is <a class="reference internal" href="#flask.json.loads" title="flask.json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a>.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.1.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_pyfile"> <span class="sig-name descname"><span class="pre">from_pyfile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">silent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_pyfile" title="Link to this definition">¶</a></dt> <dd><p>Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the <a class="reference internal" href="#flask.Config.from_object" title="flask.Config.from_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_object()</span></code></a> function.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – the filename of the config. This can either be an absolute filename or a filename relative to the root path.</p></li> <li><p><strong>silent</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – set to <code class="docutils literal notranslate"><span class="pre">True</span></code> if you want silent failure for missing files.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the file was loaded successfully.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7: </span><code class="code docutils literal notranslate"><span class="pre">silent</span></code> parameter.</p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_object"> <span class="sig-name descname"><span class="pre">from_object</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_object" title="Link to this definition">¶</a></dt> <dd><p>Updates the values from the given object. An object can be of one of the following two types:</p> <ul class="simple"> <li><p>a string: in this case the object with that name will be imported</p></li> <li><p>an actual object reference: that object is used directly</p></li> </ul> <p>Objects are usually either modules or classes. <a class="reference internal" href="#flask.Config.from_object" title="flask.Config.from_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_object()</span></code></a> loads only the uppercase attributes of the module/class. A <code class="docutils literal notranslate"><span class="pre">dict</span></code> object will not work with <a class="reference internal" href="#flask.Config.from_object" title="flask.Config.from_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_object()</span></code></a> because the keys of a <code class="docutils literal notranslate"><span class="pre">dict</span></code> are not attributes of the <code class="docutils literal notranslate"><span class="pre">dict</span></code> class.</p> <p>Example of module-based configuration:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="s1">&#39;yourapplication.default_config&#39;</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">yourapplication</span> <span class="kn">import</span> <span class="n">default_config</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="n">default_config</span><span class="p">)</span> </pre></div> </div> <p>Nothing is done to the object before loading. If the object is a class and has <code class="docutils literal notranslate"><span class="pre">&#64;property</span></code> attributes, it needs to be instantiated before being passed to this method.</p> <p>You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with <a class="reference internal" href="#flask.Config.from_pyfile" title="flask.Config.from_pyfile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_pyfile()</span></code></a> and ideally from a location not within the package because the package might be installed system wide.</p> <p>See <a class="reference internal" href="../config/#config-dev-prod"><span class="std std-ref">Development / Production</span></a> for an example of class-based configuration using <a class="reference internal" href="#flask.Config.from_object" title="flask.Config.from_object"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_object()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>obj</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.13)"><em>object</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – an import name or object</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_file"> <span class="sig-name descname"><span class="pre">from_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">silent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">text</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_file" title="Link to this definition">¶</a></dt> <dd><p>Update the values in the config from a file that is loaded using the <code class="docutils literal notranslate"><span class="pre">load</span></code> parameter. The loaded data is passed to the <a class="reference internal" href="#flask.Config.from_mapping" title="flask.Config.from_mapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_mapping()</span></code></a> method.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">json</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="s2">&quot;config.json&quot;</span><span class="p">,</span> <span class="n">load</span><span class="o">=</span><span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">)</span> <span class="kn">import</span> <span class="nn">tomllib</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="s2">&quot;config.toml&quot;</span><span class="p">,</span> <span class="n">load</span><span class="o">=</span><span class="n">tomllib</span><span class="o">.</span><span class="n">load</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> </pre></div> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – The path to the data file. This can be an absolute path or relative to the config root path.</p></li> <li><p><strong>load</strong> (<code class="docutils literal notranslate"><span class="pre">Callable[[Reader],</span> <span class="pre">Mapping]</span></code> where <code class="docutils literal notranslate"><span class="pre">Reader</span></code> implements a <code class="docutils literal notranslate"><span class="pre">read</span></code> method.) – A callable that takes a file handle and returns a mapping of loaded data from the file.</p></li> <li><p><strong>silent</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Ignore the file if it doesn’t exist.</p></li> <li><p><strong>text</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Open the file in text or binary mode.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if the file was loaded successfully.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.3: </span>The <code class="docutils literal notranslate"><span class="pre">text</span></code> parameter was added.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 2.0.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.from_mapping"> <span class="sig-name descname"><span class="pre">from_mapping</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mapping</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.from_mapping" title="Link to this definition">¶</a></dt> <dd><p>Updates the config like <code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code> ignoring items with non-upper keys.</p> <dl class="field-list simple"> <dt class="field-odd">Returns<span class="colon">:</span></dt> <dd class="field-odd"><p>Always returns <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </dd> <dt class="field-even">Parameters<span class="colon">:</span></dt> <dd class="field-even"><ul class="simple"> <li><p><strong>mapping</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Mapping" title="(in Python v3.13)"><em>Mapping</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.Config.get_namespace"> <span class="sig-name descname"><span class="pre">get_namespace</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">namespace</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lowercase</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">trim_namespace</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.Config.get_namespace" title="Link to this definition">¶</a></dt> <dd><p>Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix. Example usage:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_TYPE&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;fs&#39;</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_PATH&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/var/app/images&#39;</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s1">&#39;IMAGE_STORE_BASE_URL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;http://img.website.com&#39;</span> <span class="n">image_store_config</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">get_namespace</span><span class="p">(</span><span class="s1">&#39;IMAGE_STORE_&#39;</span><span class="p">)</span> </pre></div> </div> <p>The resulting dictionary <code class="code docutils literal notranslate"><span class="pre">image_store_config</span></code> would look like:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s1">&#39;type&#39;</span><span class="p">:</span> <span class="s1">&#39;fs&#39;</span><span class="p">,</span> <span class="s1">&#39;path&#39;</span><span class="p">:</span> <span class="s1">&#39;/var/app/images&#39;</span><span class="p">,</span> <span class="s1">&#39;base_url&#39;</span><span class="p">:</span> <span class="s1">&#39;http://img.website.com&#39;</span> <span class="p">}</span> </pre></div> </div> <p>This is often useful when configuration options map directly to keyword arguments in functions or class constructors.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>namespace</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>) – a configuration namespace</p></li> <li><p><strong>lowercase</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – a flag indicating if the keys of the resulting dictionary should be lowercase</p></li> <li><p><strong>trim_namespace</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – a flag indicating if the keys of the resulting dictionary should not include the namespace</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)">dict</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>, <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]</p> </dd> </dl> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.11.</span></p> </div> </details></dd></dl> </dd></dl> </section> <section id="stream-helpers"> <h2>Stream Helpers<a class="headerlink" href="#stream-helpers" title="Link to this heading">¶</a></h2> <dl class="py function"> <dt class="sig sig-object py" id="flask.stream_with_context"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">stream_with_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">generator_or_function</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><span class="pre">Iterator</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><span class="pre">Iterator</span></a></span></span><a class="headerlink" href="#flask.stream_with_context" title="Link to this definition">¶</a></dt> <dt class="sig sig-object py"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">stream_with_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">generator_or_function</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><span class="pre">Callable</span></a><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><span class="pre">Iterator</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><span class="pre">Callable</span></a><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><span class="pre">Iterator</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Iterator" title="(in Python v3.13)"><span class="pre">Iterator</span></a><span class="p"><span class="pre">]</span></span></span></span></dt> <dd><p>Request contexts disappear when the response is started on the server. This is done for efficiency reasons and to make it less likely to encounter memory leaks with badly written WSGI middlewares. The downside is that if you are using streamed responses, the generator cannot access request bound information any more.</p> <p>This function however can help you keep the context around for longer:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">stream_with_context</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">Response</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/stream&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span> <span class="nd">@stream_with_context</span> <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span> <span class="k">yield</span> <span class="s1">&#39;Hello &#39;</span> <span class="k">yield</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span> <span class="k">yield</span> <span class="s1">&#39;!&#39;</span> <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">generate</span><span class="p">())</span> </pre></div> </div> <p>Alternatively it can also be used around a specific generator:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">stream_with_context</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">Response</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/stream&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">streamed_response</span><span class="p">():</span> <span class="k">def</span> <span class="nf">generate</span><span class="p">():</span> <span class="k">yield</span> <span class="s1">&#39;Hello &#39;</span> <span class="k">yield</span> <span class="n">request</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span> <span class="k">yield</span> <span class="s1">&#39;!&#39;</span> <span class="k">return</span> <span class="n">Response</span><span class="p">(</span><span class="n">stream_with_context</span><span class="p">(</span><span class="n">generate</span><span class="p">()))</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.9.</span></p> </div> </details></dd></dl> </section> <section id="useful-internals"> <h2>Useful Internals<a class="headerlink" href="#useful-internals" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.ctx.RequestContext"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.ctx.</span></span><span class="sig-name descname"><span class="pre">RequestContext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">request</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">session</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.RequestContext" title="Link to this definition">¶</a></dt> <dd><p>The request context contains per-request information. The Flask app creates and pushes it at the beginning of the request, then pops it at the end of the request. It will create the URL adapter and request object for the WSGI environment provided.</p> <p>Do not attempt to use this class directly, instead use <a class="reference internal" href="#flask.Flask.test_request_context" title="flask.Flask.test_request_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">test_request_context()</span></code></a> and <a class="reference internal" href="#flask.Flask.request_context" title="flask.Flask.request_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">request_context()</span></code></a> to create this object.</p> <p>When the request context is popped, it will evaluate all the functions registered on the application for teardown execution (<a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a>).</p> <p>The request context is automatically popped at the end of the request. When using the interactive debugger, the context will be restored so <code class="docutils literal notranslate"><span class="pre">request</span></code> is still accessible. Similarly, the test client can preserve the context after the request ends. However, teardown functions may already have closed some resources such as database connections.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p></li> <li><p><strong>environ</strong> (<em>WSGIEnvironment</em>)</p></li> <li><p><strong>request</strong> (<a class="reference internal" href="#flask.Request" title="flask.Request"><em>Request</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>session</strong> (<a class="reference internal" href="#flask.sessions.SessionMixin" title="flask.sessions.SessionMixin"><em>SessionMixin</em></a><em> | </em><em>None</em>)</p></li> </ul> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx.RequestContext.copy"> <span class="sig-name descname"><span class="pre">copy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.RequestContext.copy" title="Link to this definition">¶</a></dt> <dd><p>Creates a copy of this request context with the same request object. This can be used to move a request context to a different greenlet. Because the actual request object is the same this cannot be used to move a request context to a different thread unless access to the request object is locked.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1: </span>The current session object is used instead of reloading the original data. This prevents <code class="code docutils literal notranslate"><span class="pre">flask.session</span></code> pointing to an out-of-date object.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><em>RequestContext</em></a></p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx.RequestContext.match_request"> <span class="sig-name descname"><span class="pre">match_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.RequestContext.match_request" title="Link to this definition">¶</a></dt> <dd><p>Can be overridden by a subclass to hook into the matching of the request.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx.RequestContext.pop"> <span class="sig-name descname"><span class="pre">pop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.RequestContext.pop" title="Link to this definition">¶</a></dt> <dd><p>Pops the request context and unbinds it by doing that. This will also trigger the execution of functions registered by the <a class="reference internal" href="#flask.Flask.teardown_request" title="flask.Flask.teardown_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">teardown_request()</span></code></a> decorator.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 0.9: </span>Added the <code class="code docutils literal notranslate"><span class="pre">exc</span></code> argument.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>exc</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.flask.globals.request_ctx"> <span class="sig-prename descclassname"><span class="pre">flask.globals.</span></span><span class="sig-name descname"><span class="pre">request_ctx</span></span><a class="headerlink" href="#flask.flask.globals.request_ctx" title="Link to this definition">¶</a></dt> <dd><p>The current <a class="reference internal" href="#flask.ctx.RequestContext" title="flask.ctx.RequestContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">RequestContext</span></code></a>. If a request context is not active, accessing attributes on this proxy will raise a <code class="docutils literal notranslate"><span class="pre">RuntimeError</span></code>.</p> <p>This is an internal object that is essential to how Flask handles requests. Accessing this should not be needed in most cases. Most likely you want <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-data docutils literal notranslate"><span class="pre">request</span></code></a> and <a class="reference internal" href="#flask.session" title="flask.session"><code class="xref py py-data docutils literal notranslate"><span class="pre">session</span></code></a> instead.</p> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.ctx.AppContext"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.ctx.</span></span><span class="sig-name descname"><span class="pre">AppContext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.AppContext" title="Link to this definition">¶</a></dt> <dd><p>The app context contains application-specific information. An app context is created and pushed at the beginning of each request if one is not already active. An app context is also pushed when running CLI commands.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>app</strong> (<a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a>)</p> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx.AppContext.push"> <span class="sig-name descname"><span class="pre">push</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.AppContext.push" title="Link to this definition">¶</a></dt> <dd><p>Binds the app context to the current context.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.ctx.AppContext.pop"> <span class="sig-name descname"><span class="pre">pop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">exc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">_sentinel</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.ctx.AppContext.pop" title="Link to this definition">¶</a></dt> <dd><p>Pops the app context.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>exc</strong> (<a class="reference external" href="https://docs.python.org/3/library/exceptions.html#BaseException" title="(in Python v3.13)"><em>BaseException</em></a><em> | </em><em>None</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.flask.globals.app_ctx"> <span class="sig-prename descclassname"><span class="pre">flask.globals.</span></span><span class="sig-name descname"><span class="pre">app_ctx</span></span><a class="headerlink" href="#flask.flask.globals.app_ctx" title="Link to this definition">¶</a></dt> <dd><p>The current <a class="reference internal" href="#flask.ctx.AppContext" title="flask.ctx.AppContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppContext</span></code></a>. If an app context is not active, accessing attributes on this proxy will raise a <code class="docutils literal notranslate"><span class="pre">RuntimeError</span></code>.</p> <p>This is an internal object that is essential to how Flask handles requests. Accessing this should not be needed in most cases. Most likely you want <a class="reference internal" href="#flask.current_app" title="flask.current_app"><code class="xref py py-data docutils literal notranslate"><span class="pre">current_app</span></code></a> and <a class="reference internal" href="#flask.g" title="flask.g"><code class="xref py py-data docutils literal notranslate"><span class="pre">g</span></code></a> instead.</p> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.blueprints.</span></span><span class="sig-name descname"><span class="pre">BlueprintSetupState</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">blueprint</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">app</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">options</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">first_registration</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState" title="Link to this definition">¶</a></dt> <dd><p>Temporary holder object for registering a blueprint with the application. An instance of this class is created by the <a class="reference internal" href="#flask.Blueprint.make_setup_state" title="flask.Blueprint.make_setup_state"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_setup_state()</span></code></a> method and later passed to all register callback functions.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>blueprint</strong> (<a class="reference internal" href="#flask.Blueprint" title="flask.blueprints.Blueprint"><em>Blueprint</em></a>)</p></li> <li><p><strong>app</strong> (<em>App</em>)</p></li> <li><p><strong>options</strong> (<em>t.Any</em>)</p></li> <li><p><strong>first_registration</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.app"> <span class="sig-name descname"><span class="pre">app</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.app" title="Link to this definition">¶</a></dt> <dd><p>a reference to the current application</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.blueprint"> <span class="sig-name descname"><span class="pre">blueprint</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.blueprint" title="Link to this definition">¶</a></dt> <dd><p>a reference to the blueprint that created this setup state.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.options"> <span class="sig-name descname"><span class="pre">options</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.options" title="Link to this definition">¶</a></dt> <dd><p>a dictionary with all options that were passed to the <a class="reference internal" href="#flask.Flask.register_blueprint" title="flask.Flask.register_blueprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">register_blueprint()</span></code></a> method.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.first_registration"> <span class="sig-name descname"><span class="pre">first_registration</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.first_registration" title="Link to this definition">¶</a></dt> <dd><p>as blueprints can be registered multiple times with the application and not everything wants to be registered multiple times on it, this attribute can be used to figure out if the blueprint was registered in the past already.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.subdomain"> <span class="sig-name descname"><span class="pre">subdomain</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.subdomain" title="Link to this definition">¶</a></dt> <dd><p>The subdomain that the blueprint should be active for, <code class="docutils literal notranslate"><span class="pre">None</span></code> otherwise.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.url_prefix"> <span class="sig-name descname"><span class="pre">url_prefix</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.url_prefix" title="Link to this definition">¶</a></dt> <dd><p>The prefix that should be used for all URLs defined on the blueprint.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.url_defaults"> <span class="sig-name descname"><span class="pre">url_defaults</span></span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.url_defaults" title="Link to this definition">¶</a></dt> <dd><p>A dictionary with URL defaults that is added to each and every URL that was defined with the blueprint.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.blueprints.BlueprintSetupState.add_url_rule"> <span class="sig-name descname"><span class="pre">add_url_rule</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rule</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">endpoint</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">view_func</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">options</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.blueprints.BlueprintSetupState.add_url_rule" title="Link to this definition">¶</a></dt> <dd><p>A helper method to register a rule (and optionally a view function) to the application. The endpoint is automatically prefixed with the blueprint’s name.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>rule</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>endpoint</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>view_func</strong> (<em>ft.RouteCallable</em><em> | </em><em>None</em>)</p></li> <li><p><strong>options</strong> (<em>t.Any</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>None</p> </dd> </dl> </dd></dl> </dd></dl> </section> <section id="signals"> <span id="core-signals-list"></span><h2>Signals<a class="headerlink" href="#signals" title="Link to this heading">¶</a></h2> <p>Signals are provided by the <a class="reference external" href="https://blinker.readthedocs.io/">Blinker</a> library. See <a class="reference internal" href="../signals/"><span class="doc">Signals</span></a> for an introduction.</p> <dl class="py data"> <dt class="sig sig-object py" id="flask.template_rendered"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">template_rendered</span></span><a class="headerlink" href="#flask.template_rendered" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when a template was successfully rendered. The signal is invoked with the instance of the template as <code class="code docutils literal notranslate"><span class="pre">template</span></code> and the context as dictionary (named <code class="code docutils literal notranslate"><span class="pre">context</span></code>).</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">log_template_renders</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">template</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">sender</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Rendering template &quot;</span><span class="si">%s</span><span class="s1">&quot; with context </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">template</span><span class="o">.</span><span class="n">name</span> <span class="ow">or</span> <span class="s1">&#39;string template&#39;</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">template_rendered</span> <span class="n">template_rendered</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">log_template_renders</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">before_render_template</span></span></dt> <dd><p>This signal is sent before template rendering process. The signal is invoked with the instance of the template as <code class="code docutils literal notranslate"><span class="pre">template</span></code> and the context as dictionary (named <code class="code docutils literal notranslate"><span class="pre">context</span></code>).</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">log_template_renders</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">template</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">sender</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Rendering template &quot;</span><span class="si">%s</span><span class="s1">&quot; with context </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">template</span><span class="o">.</span><span class="n">name</span> <span class="ow">or</span> <span class="s1">&#39;string template&#39;</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">before_render_template</span> <span class="n">before_render_template</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">log_template_renders</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.request_started"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">request_started</span></span><a class="headerlink" href="#flask.request_started" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when the request context is set up, before any request processing happens. Because the request context is already bound, the subscriber can access the request with the standard global proxies such as <a class="reference internal" href="#flask.request" title="flask.request"><code class="xref py py-class docutils literal notranslate"><span class="pre">request</span></code></a>.</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">log_request</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">sender</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Request context is set up&#39;</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">request_started</span> <span class="n">request_started</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">log_request</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.request_finished"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">request_finished</span></span><a class="headerlink" href="#flask.request_finished" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent right before the response is sent to the client. It is passed the response to be sent named <code class="code docutils literal notranslate"><span class="pre">response</span></code>.</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">log_response</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">sender</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Request context is about to close down. &#39;</span> <span class="s1">&#39;Response: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">request_finished</span> <span class="n">request_finished</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">log_response</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.got_request_exception"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">got_request_exception</span></span><a class="headerlink" href="#flask.got_request_exception" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when an unhandled exception happens during request processing, including when debugging. The exception is passed to the subscriber as <code class="docutils literal notranslate"><span class="pre">exception</span></code>.</p> <p>This signal is not sent for <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/exceptions/#werkzeug.exceptions.HTTPException" title="(in Werkzeug v3.1.x)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">HTTPException</span></code></a>, or other exceptions that have error handlers registered, unless the exception was raised from an error handler.</p> <p>This example shows how to do some extra logging if a theoretical <code class="docutils literal notranslate"><span class="pre">SecurityException</span></code> was raised:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">got_request_exception</span> <span class="k">def</span> <span class="nf">log_security_exception</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">exception</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">exception</span><span class="p">,</span> <span class="n">SecurityException</span><span class="p">):</span> <span class="k">return</span> <span class="n">security_logger</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span> <span class="sa">f</span><span class="s2">&quot;SecurityException at </span><span class="si">{</span><span class="n">request</span><span class="o">.</span><span class="n">url</span><span class="si">!r}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">exc_info</span><span class="o">=</span><span class="n">exception</span><span class="p">,</span> <span class="p">)</span> <span class="n">got_request_exception</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">log_security_exception</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.request_tearing_down"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">request_tearing_down</span></span><a class="headerlink" href="#flask.request_tearing_down" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when the request is tearing down. This is always called, even if an exception is caused. Currently functions listening to this signal are called after the regular teardown handlers, but this is not something you can rely on.</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">close_db_connection</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">session</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">request_tearing_down</span> <span class="n">request_tearing_down</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">close_db_connection</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> <p>As of Flask 0.9, this will also be passed an <code class="code docutils literal notranslate"><span class="pre">exc</span></code> keyword argument that has a reference to the exception that caused the teardown if there was one.</p> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.appcontext_tearing_down"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">appcontext_tearing_down</span></span><a class="headerlink" href="#flask.appcontext_tearing_down" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when the app context is tearing down. This is always called, even if an exception is caused. Currently functions listening to this signal are called after the regular teardown handlers, but this is not something you can rely on.</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">close_db_connection</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">session</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">appcontext_tearing_down</span> <span class="n">appcontext_tearing_down</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">close_db_connection</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> <p>This will also be passed an <code class="code docutils literal notranslate"><span class="pre">exc</span></code> keyword argument that has a reference to the exception that caused the teardown if there was one.</p> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.appcontext_pushed"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">appcontext_pushed</span></span><a class="headerlink" href="#flask.appcontext_pushed" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when an application context is pushed. The sender is the application. This is usually useful for unittests in order to temporarily hook in information. For instance it can be used to set a resource early onto the <code class="code docutils literal notranslate"><span class="pre">g</span></code> object.</p> <p>Example usage:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">contextlib</span> <span class="kn">import</span> <span class="n">contextmanager</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">appcontext_pushed</span> <span class="nd">@contextmanager</span> <span class="k">def</span> <span class="nf">user_set</span><span class="p">(</span><span class="n">app</span><span class="p">,</span> <span class="n">user</span><span class="p">):</span> <span class="k">def</span> <span class="nf">handler</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="n">g</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">user</span> <span class="k">with</span> <span class="n">appcontext_pushed</span><span class="o">.</span><span class="n">connected_to</span><span class="p">(</span><span class="n">handler</span><span class="p">,</span> <span class="n">app</span><span class="p">):</span> <span class="k">yield</span> </pre></div> </div> <p>And in the testcode:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">test_user_me</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">with</span> <span class="n">user_set</span><span class="p">(</span><span class="n">app</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">):</span> <span class="n">c</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">test_client</span><span class="p">()</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;/users/me&#39;</span><span class="p">)</span> <span class="k">assert</span> <span class="n">resp</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="s1">&#39;username=john&#39;</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.appcontext_popped"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">appcontext_popped</span></span><a class="headerlink" href="#flask.appcontext_popped" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when an application context is popped. The sender is the application. This usually falls in line with the <a class="reference internal" href="#flask.appcontext_tearing_down" title="flask.appcontext_tearing_down"><code class="xref py py-data docutils literal notranslate"><span class="pre">appcontext_tearing_down</span></code></a> signal.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.message_flashed"> <span class="sig-prename descclassname"><span class="pre">flask.</span></span><span class="sig-name descname"><span class="pre">message_flashed</span></span><a class="headerlink" href="#flask.message_flashed" title="Link to this definition">¶</a></dt> <dd><p>This signal is sent when the application is flashing a message. The messages is sent as <code class="code docutils literal notranslate"><span class="pre">message</span></code> keyword argument and the category as <code class="code docutils literal notranslate"><span class="pre">category</span></code>.</p> <p>Example subscriber:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">recorded</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">def</span> <span class="nf">record</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">category</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="n">recorded</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">message</span><span class="p">,</span> <span class="n">category</span><span class="p">))</span> <span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">message_flashed</span> <span class="n">message_flashed</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">app</span><span class="p">)</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.10.</span></p> </div> </details></dd></dl> </section> <section id="class-based-views"> <h2>Class-Based Views<a class="headerlink" href="#class-based-views" title="Link to this heading">¶</a></h2> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.7.</span></p> </div> </details><dl class="py class"> <dt class="sig sig-object py" id="flask.views.View"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.views.</span></span><span class="sig-name descname"><span class="pre">View</span></span><a class="headerlink" href="#flask.views.View" title="Link to this definition">¶</a></dt> <dd><p>Subclass this class and override <a class="reference internal" href="#flask.views.View.dispatch_request" title="flask.views.View.dispatch_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_request()</span></code></a> to create a generic class-based view. Call <a class="reference internal" href="#flask.views.View.as_view" title="flask.views.View.as_view"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_view()</span></code></a> to create a view function that creates an instance of the class with the given arguments and calls its <code class="docutils literal notranslate"><span class="pre">dispatch_request</span></code> method with any URL variables.</p> <p>See <a class="reference internal" href="../views/"><span class="doc">Class-based Views</span></a> for a detailed guide.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Hello</span><span class="p">(</span><span class="n">View</span><span class="p">):</span> <span class="n">init_every_request</span> <span class="o">=</span> <span class="kc">False</span> <span class="k">def</span> <span class="nf">dispatch_request</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span> <span class="k">return</span> <span class="sa">f</span><span class="s2">&quot;Hello, </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">!&quot;</span> <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span> <span class="s2">&quot;/hello/&lt;name&gt;&quot;</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="n">Hello</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="s2">&quot;hello&quot;</span><span class="p">)</span> <span class="p">)</span> </pre></div> </div> <p>Set <a class="reference internal" href="#flask.views.View.methods" title="flask.views.View.methods"><code class="xref py py-attr docutils literal notranslate"><span class="pre">methods</span></code></a> on the class to change what methods the view accepts.</p> <p>Set <a class="reference internal" href="#flask.views.View.decorators" title="flask.views.View.decorators"><code class="xref py py-attr docutils literal notranslate"><span class="pre">decorators</span></code></a> on the class to apply a list of decorators to the generated view function. Decorators applied to the class itself will not be applied to the generated view function!</p> <p>Set <a class="reference internal" href="#flask.views.View.init_every_request" title="flask.views.View.init_every_request"><code class="xref py py-attr docutils literal notranslate"><span class="pre">init_every_request</span></code></a> to <code class="docutils literal notranslate"><span class="pre">False</span></code> for efficiency, unless you need to store request-global data on <code class="docutils literal notranslate"><span class="pre">self</span></code>.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.views.View.methods"> <span class="sig-name descname"><span class="pre">methods</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.ClassVar" title="(in Python v3.13)"><span class="pre">ClassVar</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Collection" title="(in Python v3.13)"><span class="pre">Collection</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><span class="pre">str</span></a><span class="p"><span class="pre">]</span></span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.views.View.methods" title="Link to this definition">¶</a></dt> <dd><p>The methods this view is registered for. Uses the same default (<code class="docutils literal notranslate"><span class="pre">[&quot;GET&quot;,</span> <span class="pre">&quot;HEAD&quot;,</span> <span class="pre">&quot;OPTIONS&quot;]</span></code>) as <code class="docutils literal notranslate"><span class="pre">route</span></code> and <code class="docutils literal notranslate"><span class="pre">add_url_rule</span></code> by default.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.views.View.provide_automatic_options"> <span class="sig-name descname"><span class="pre">provide_automatic_options</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.ClassVar" title="(in Python v3.13)"><span class="pre">ClassVar</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(in Python v3.13)"><span class="pre">None</span></a><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">None</span></em><a class="headerlink" href="#flask.views.View.provide_automatic_options" title="Link to this definition">¶</a></dt> <dd><p>Control whether the <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> method is handled automatically. Uses the same default (<code class="docutils literal notranslate"><span class="pre">True</span></code>) as <code class="docutils literal notranslate"><span class="pre">route</span></code> and <code class="docutils literal notranslate"><span class="pre">add_url_rule</span></code> by default.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.views.View.decorators"> <span class="sig-name descname"><span class="pre">decorators</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.ClassVar" title="(in Python v3.13)"><span class="pre">ClassVar</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><span class="pre">list</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><span class="pre">Callable</span></a><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">[</span></span><span class="p"><span class="pre">...</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">,</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><span class="pre">Any</span></a><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[]</span></em><a class="headerlink" href="#flask.views.View.decorators" title="Link to this definition">¶</a></dt> <dd><p>A list of decorators to apply, in order, to the generated view function. Remember that <code class="docutils literal notranslate"><span class="pre">&#64;decorator</span></code> syntax is applied bottom to top, so the first decorator in the list would be the bottom decorator.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8.</span></p> </div> </details></dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.views.View.init_every_request"> <span class="sig-name descname"><span class="pre">init_every_request</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.ClassVar" title="(in Python v3.13)"><span class="pre">ClassVar</span></a><span class="p"><span class="pre">[</span></span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><span class="pre">bool</span></a><span class="p"><span class="pre">]</span></span></em><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">True</span></em><a class="headerlink" href="#flask.views.View.init_every_request" title="Link to this definition">¶</a></dt> <dd><p>Create a new instance of this view class for every request by default. If a view subclass sets this to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the same instance is used for every request.</p> <p>A single instance is more efficient, especially if complex setup is done during init. However, storing data on <code class="docutils literal notranslate"><span class="pre">self</span></code> is no longer safe across requests, and <a class="reference internal" href="#flask.g" title="flask.g"><code class="xref py py-data docutils literal notranslate"><span class="pre">g</span></code></a> should be used instead.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 2.2.</span></p> </div> </details></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.views.View.dispatch_request"> <span class="sig-name descname"><span class="pre">dispatch_request</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.views.View.dispatch_request" title="Link to this definition">¶</a></dt> <dd><p>The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p>ft.ResponseReturnValue</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.views.View.as_view"> <em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">as_view</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">class_args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">class_kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.views.View.as_view" title="Link to this definition">¶</a></dt> <dd><p>Convert the class into a view function that can be registered for a route.</p> <p>By default, the generated view will create a new instance of the view class for every request and call its <a class="reference internal" href="#flask.views.View.dispatch_request" title="flask.views.View.dispatch_request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dispatch_request()</span></code></a> method. If the view class sets <a class="reference internal" href="#flask.views.View.init_every_request" title="flask.views.View.init_every_request"><code class="xref py py-attr docutils literal notranslate"><span class="pre">init_every_request</span></code></a> to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the same instance will be used for every request.</p> <p>Except for <code class="docutils literal notranslate"><span class="pre">name</span></code>, all other arguments passed to this method are forwarded to the view class <code class="docutils literal notranslate"><span class="pre">__init__</span></code> method.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Added the <code class="docutils literal notranslate"><span class="pre">init_every_request</span></code> class attribute.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> <li><p><strong>class_args</strong> (<em>t.Any</em>)</p></li> <li><p><strong>class_kwargs</strong> (<em>t.Any</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>ft.RouteCallable</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.views.MethodView"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.views.</span></span><span class="sig-name descname"><span class="pre">MethodView</span></span><a class="headerlink" href="#flask.views.MethodView" title="Link to this definition">¶</a></dt> <dd><p>Dispatches request methods to the corresponding instance methods. For example, if you implement a <code class="docutils literal notranslate"><span class="pre">get</span></code> method, it will be used to handle <code class="docutils literal notranslate"><span class="pre">GET</span></code> requests.</p> <p>This can be useful for defining a REST API.</p> <p><code class="xref py py-attr docutils literal notranslate"><span class="pre">methods</span></code> is automatically set based on the methods defined on the class.</p> <p>See <a class="reference internal" href="../views/"><span class="doc">Class-based Views</span></a> for a detailed guide.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CounterAPI</span><span class="p">(</span><span class="n">MethodView</span><span class="p">):</span> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;counter&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span> <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="n">session</span><span class="p">[</span><span class="s2">&quot;counter&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;counter&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">return</span> <span class="n">redirect</span><span class="p">(</span><span class="n">url_for</span><span class="p">(</span><span class="s2">&quot;counter&quot;</span><span class="p">))</span> <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span> <span class="s2">&quot;/counter&quot;</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="n">CounterAPI</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="s2">&quot;counter&quot;</span><span class="p">)</span> <span class="p">)</span> </pre></div> </div> <dl class="py method"> <dt class="sig sig-object py" id="flask.views.MethodView.dispatch_request"> <span class="sig-name descname"><span class="pre">dispatch_request</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.views.MethodView.dispatch_request" title="Link to this definition">¶</a></dt> <dd><p>The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>kwargs</strong> (<em>t.Any</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>ft.ResponseReturnValue</p> </dd> </dl> </dd></dl> </dd></dl> </section> <section id="url-route-registrations"> <span id="id1"></span><h2>URL Route Registrations<a class="headerlink" href="#url-route-registrations" title="Link to this heading">¶</a></h2> <p>Generally there are three ways to define rules for the routing system:</p> <ol class="arabic simple"> <li><p>You can use the <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flask.Flask.route()</span></code></a> decorator.</p></li> <li><p>You can use the <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flask.Flask.add_url_rule()</span></code></a> function.</p></li> <li><p>You can directly access the underlying Werkzeug routing system which is exposed as <a class="reference internal" href="#flask.Flask.url_map" title="flask.Flask.url_map"><code class="xref py py-attr docutils literal notranslate"><span class="pre">flask.Flask.url_map</span></code></a>.</p></li> </ol> <p>Variable parts in the route can be specified with angular brackets (<code class="docutils literal notranslate"><span class="pre">/user/&lt;username&gt;</span></code>). By default a variable part in the URL accepts any string without a slash however a different converter can be specified as well by using <code class="docutils literal notranslate"><span class="pre">&lt;converter:name&gt;</span></code>.</p> <p>Variable parts are passed to the view function as keyword arguments.</p> <p>The following converters are available:</p> <table class="docutils align-default"> <tbody> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">string</span></code></p></td> <td><p>accepts any text without a slash (the default)</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">int</span></code></p></td> <td><p>accepts integers</p></td> </tr> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">float</span></code></p></td> <td><p>like <code class="code docutils literal notranslate"><span class="pre">int</span></code> but for floating point values</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">path</span></code></p></td> <td><p>like the default but also accepts slashes</p></td> </tr> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">any</span></code></p></td> <td><p>matches one of the items provided</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">uuid</span></code></p></td> <td><p>accepts UUID strings</p></td> </tr> </tbody> </table> <p>Custom converters can be defined using <a class="reference internal" href="#flask.Flask.url_map" title="flask.Flask.url_map"><code class="xref py py-attr docutils literal notranslate"><span class="pre">flask.Flask.url_map</span></code></a>.</p> <p>Here are some examples:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="k">pass</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&lt;username&gt;&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">show_user</span><span class="p">(</span><span class="n">username</span><span class="p">):</span> <span class="k">pass</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/post/&lt;int:post_id&gt;&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">show_post</span><span class="p">(</span><span class="n">post_id</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> <p>An important detail to keep in mind is how Flask deals with trailing slashes. The idea is to keep each URL unique so the following rules apply:</p> <ol class="arabic simple"> <li><p>If a rule ends with a slash and is requested without a slash by the user, the user is automatically redirected to the same page with a trailing slash attached.</p></li> <li><p>If a rule does not end with a trailing slash and the user requests the page with a trailing slash, a 404 not found is raised.</p></li> </ol> <p>This is consistent with how web servers deal with static files. This also makes it possible to use relative link targets safely.</p> <p>You can also define multiple rules for the same function. They have to be unique however. Defaults can also be specified. Here for example is a definition for a URL that accepts an optional page:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/users/&#39;</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;page&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/users/page/&lt;int:page&gt;&#39;</span><span class="p">)</span> <span class="k">def</span> <span class="nf">show_users</span><span class="p">(</span><span class="n">page</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> <p>This specifies that <code class="docutils literal notranslate"><span class="pre">/users/</span></code> will be the URL for page one and <code class="docutils literal notranslate"><span class="pre">/users/page/N</span></code> will be the URL for page <code class="docutils literal notranslate"><span class="pre">N</span></code>.</p> <p>If a URL contains a default value, it will be redirected to its simpler form with a 301 redirect. In the above example, <code class="docutils literal notranslate"><span class="pre">/users/page/1</span></code> will be redirected to <code class="docutils literal notranslate"><span class="pre">/users/</span></code>. If your route handles <code class="docutils literal notranslate"><span class="pre">GET</span></code> and <code class="docutils literal notranslate"><span class="pre">POST</span></code> requests, make sure the default route only handles <code class="docutils literal notranslate"><span class="pre">GET</span></code>, as redirects can’t preserve form data.</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/region/&#39;</span><span class="p">,</span> <span class="n">defaults</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">})</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/region/&lt;int:id&gt;&#39;</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="s1">&#39;POST&#39;</span><span class="p">])</span> <span class="k">def</span> <span class="nf">region</span><span class="p">(</span><span class="nb">id</span><span class="p">):</span> <span class="k">pass</span> </pre></div> </div> <p>Here are the parameters that <a class="reference internal" href="#flask.Flask.route" title="flask.Flask.route"><code class="xref py py-meth docutils literal notranslate"><span class="pre">route()</span></code></a> and <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a> accept. The only difference is that with the route parameter the view function is defined with the decorator instead of the <code class="code docutils literal notranslate"><span class="pre">view_func</span></code> parameter.</p> <table class="docutils align-default"> <tbody> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">rule</span></code></p></td> <td><p>the URL rule as string</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">endpoint</span></code></p></td> <td><p>the endpoint for the registered URL rule. Flask itself assumes that the name of the view function is the name of the endpoint if not explicitly stated.</p></td> </tr> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">view_func</span></code></p></td> <td><p>the function to call when serving a request to the provided endpoint. If this is not provided one can specify the function later by storing it in the <a class="reference internal" href="#flask.Flask.view_functions" title="flask.Flask.view_functions"><code class="xref py py-attr docutils literal notranslate"><span class="pre">view_functions</span></code></a> dictionary with the endpoint as key.</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">defaults</span></code></p></td> <td><p>A dictionary with defaults for this rule. See the example above for how defaults work.</p></td> </tr> <tr class="row-odd"><td><p><code class="code docutils literal notranslate"><span class="pre">subdomain</span></code></p></td> <td><p>specifies the rule for the subdomain in case subdomain matching is in use. If not specified the default subdomain is assumed.</p></td> </tr> <tr class="row-even"><td><p><code class="code docutils literal notranslate"><span class="pre">**options</span></code></p></td> <td><p>the options to be forwarded to the underlying <a class="reference external" href="https://werkzeug.palletsprojects.com/en/stable/routing/#werkzeug.routing.Rule" title="(in Werkzeug v3.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a> object. A change to Werkzeug is handling of method options. methods is a list of methods this rule should be limited to (<code class="docutils literal notranslate"><span class="pre">GET</span></code>, <code class="docutils literal notranslate"><span class="pre">POST</span></code> etc.). By default a rule just listens for <code class="docutils literal notranslate"><span class="pre">GET</span></code> (and implicitly <code class="docutils literal notranslate"><span class="pre">HEAD</span></code>). Starting with Flask 0.6, <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> is implicitly added and handled by the standard request handling. They have to be specified as keyword arguments.</p></td> </tr> </tbody> </table> </section> <section id="view-function-options"> <h2>View Function Options<a class="headerlink" href="#view-function-options" title="Link to this heading">¶</a></h2> <p>For internal usage the view functions can have some attributes attached to customize behavior the view function would normally not have control over. The following attributes can be provided optionally to either override some defaults to <a class="reference internal" href="#flask.Flask.add_url_rule" title="flask.Flask.add_url_rule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_url_rule()</span></code></a> or general behavior:</p> <ul class="simple"> <li><p><code class="code docutils literal notranslate"><span class="pre">__name__</span></code>: The name of a function is by default used as endpoint. If endpoint is provided explicitly this value is used. Additionally this will be prefixed with the name of the blueprint by default which cannot be customized from the function itself.</p></li> <li><p><code class="code docutils literal notranslate"><span class="pre">methods</span></code>: If methods are not provided when the URL rule is added, Flask will look on the view function object itself if a <code class="code docutils literal notranslate"><span class="pre">methods</span></code> attribute exists. If it does, it will pull the information for the methods from there.</p></li> <li><p><code class="code docutils literal notranslate"><span class="pre">provide_automatic_options</span></code>: if this attribute is set Flask will either force enable or disable the automatic implementation of the HTTP <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> response. This can be useful when working with decorators that want to customize the <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code> response on a per-view basis.</p></li> <li><p><code class="code docutils literal notranslate"><span class="pre">required_methods</span></code>: if this attribute is set, Flask will always add these methods when registering a URL rule even if the methods were explicitly overridden in the <code class="docutils literal notranslate"><span class="pre">route()</span></code> call.</p></li> </ul> <p>Full example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span> <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;OPTIONS&#39;</span><span class="p">:</span> <span class="c1"># custom options handling here</span> <span class="o">...</span> <span class="k">return</span> <span class="s1">&#39;Hello World!&#39;</span> <span class="n">index</span><span class="o">.</span><span class="n">provide_automatic_options</span> <span class="o">=</span> <span class="kc">False</span> <span class="n">index</span><span class="o">.</span><span class="n">methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="s1">&#39;OPTIONS&#39;</span><span class="p">]</span> <span class="n">app</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">index</span><span class="p">)</span> </pre></div> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionadded"> <p><span class="versionmodified added">Added in version 0.8: </span>The <code class="code docutils literal notranslate"><span class="pre">provide_automatic_options</span></code> functionality was added.</p> </div> </details></section> <section id="command-line-interface"> <h2>Command Line Interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="flask.cli.FlaskGroup"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">FlaskGroup</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">add_default_commands</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">create_app</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">add_version_option</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_dotenv</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">set_debug_flag</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">extra</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.FlaskGroup" title="Link to this definition">¶</a></dt> <dd><p>Special subclass of the <a class="reference internal" href="#flask.cli.AppGroup" title="flask.cli.AppGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppGroup</span></code></a> group that supports loading more commands from the configured Flask app. Normally a developer does not have to interface with this class but there are some very advanced use cases for which it makes sense to create an instance of this. see <a class="reference internal" href="../cli/#custom-scripts"><span class="std std-ref">Custom Scripts</span></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>add_default_commands</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – if this is True then the default run and shell commands will be added.</p></li> <li><p><strong>add_version_option</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – adds the <code class="docutils literal notranslate"><span class="pre">--version</span></code> option.</p></li> <li><p><strong>create_app</strong> (<em>t.Callable</em><em>[</em><em>...</em><em>, </em><a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a><em>] </em><em>| </em><em>None</em>) – an optional callback that is passed the script info and returns the loaded app.</p></li> <li><p><strong>load_dotenv</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Load the nearest <code class="file docutils literal notranslate"><span class="pre">.env</span></code> and <code class="file docutils literal notranslate"><span class="pre">.flaskenv</span></code> files to set environment variables. Will also change the working directory to the directory containing the first file found.</p></li> <li><p><strong>set_debug_flag</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Set the app’s debug flag.</p></li> <li><p><strong>extra</strong> (<em>t.Any</em>)</p></li> </ul> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span><code class="docutils literal notranslate"><span class="pre">-e</span> <span class="pre">path</span></code> takes precedence over default <code class="docutils literal notranslate"><span class="pre">.env</span></code> and <code class="docutils literal notranslate"><span class="pre">.flaskenv</span></code> files.</p> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>Added the <code class="docutils literal notranslate"><span class="pre">-A/--app</span></code>, <code class="docutils literal notranslate"><span class="pre">--debug/--no-debug</span></code>, <code class="docutils literal notranslate"><span class="pre">-e/--env-file</span></code> options.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>An app context is pushed when running <code class="docutils literal notranslate"><span class="pre">app.cli</span></code> commands, so <code class="docutils literal notranslate"><span class="pre">&#64;with_appcontext</span></code> is no longer required for those commands.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.0: </span>If installed, python-dotenv will be used to load environment variables from <code class="file docutils literal notranslate"><span class="pre">.env</span></code> and <code class="file docutils literal notranslate"><span class="pre">.flaskenv</span></code> files.</p> </div> </details><dl class="py method"> <dt class="sig sig-object py" id="flask.cli.FlaskGroup.get_command"> <span class="sig-name descname"><span class="pre">get_command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ctx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.FlaskGroup.get_command" title="Link to this definition">¶</a></dt> <dd><p>Given a context and a command name, this returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code> object if it exists or returns <code class="code docutils literal notranslate"><span class="pre">None</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>ctx</strong> (<a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Context" title="(in Click v8.1.x)"><em>Context</em></a>)</p></li> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Command" title="(in Click v8.1.x)"><em>Command</em></a> | None</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.FlaskGroup.list_commands"> <span class="sig-name descname"><span class="pre">list_commands</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ctx</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.FlaskGroup.list_commands" title="Link to this definition">¶</a></dt> <dd><p>Returns a list of subcommand names in the order they should appear.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>ctx</strong> (<a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Context" title="(in Click v8.1.x)"><em>Context</em></a>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)">list</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.FlaskGroup.make_context"> <span class="sig-name descname"><span class="pre">make_context</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">info_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parent</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">extra</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.FlaskGroup.make_context" title="Link to this definition">¶</a></dt> <dd><p>This function when given an info name and arguments will kick off the parsing and create a new <code class="xref py py-class docutils literal notranslate"><span class="pre">Context</span></code>. It does not invoke the actual command callback though.</p> <p>To quickly customize the context class used without overriding this method, set the <code class="xref py py-attr docutils literal notranslate"><span class="pre">context_class</span></code> attribute.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>info_name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>) – the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it’s usually the name of the script, for commands below it’s the name of the command.</p></li> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><em>list</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>) – the arguments to parse as list of strings.</p></li> <li><p><strong>parent</strong> (<a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Context" title="(in Click v8.1.x)"><em>Context</em></a><em> | </em><em>None</em>) – the parent context if available.</p></li> <li><p><strong>extra</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>) – extra keyword arguments forwarded to the context constructor.</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Context" title="(in Click v8.1.x)"><em>Context</em></a></p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 8.0: </span>Added the <code class="xref py py-attr docutils literal notranslate"><span class="pre">context_class</span></code> attribute.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.FlaskGroup.parse_args"> <span class="sig-name descname"><span class="pre">parse_args</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ctx</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.FlaskGroup.parse_args" title="Link to this definition">¶</a></dt> <dd><p>Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by <a class="reference internal" href="#flask.cli.FlaskGroup.make_context" title="flask.cli.FlaskGroup.make_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_context()</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>ctx</strong> (<a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Context" title="(in Click v8.1.x)"><em>Context</em></a>)</p></li> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)"><em>list</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>]</em>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.13)">list</a>[<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)">str</a>]</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.cli.AppGroup"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">AppGroup</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">commands</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">attrs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.AppGroup" title="Link to this definition">¶</a></dt> <dd><p>This works similar to a regular click <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Group" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Group</span></code></a> but it changes the behavior of the <a class="reference internal" href="#flask.cli.AppGroup.command" title="flask.cli.AppGroup.command"><code class="xref py py-meth docutils literal notranslate"><span class="pre">command()</span></code></a> decorator so that it automatically wraps the functions in <a class="reference internal" href="#flask.cli.with_appcontext" title="flask.cli.with_appcontext"><code class="xref py py-func docutils literal notranslate"><span class="pre">with_appcontext()</span></code></a>.</p> <p>Not to be confused with <a class="reference internal" href="#flask.cli.FlaskGroup" title="flask.cli.FlaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskGroup</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>name</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>commands</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.MutableMapping" title="(in Python v3.13)"><em>MutableMapping</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>, </em><a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Command" title="(in Click v8.1.x)"><em>Command</em></a><em>] </em><em>| </em><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Sequence" title="(in Python v3.13)"><em>Sequence</em></a><em>[</em><a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Command" title="(in Click v8.1.x)"><em>Command</em></a><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>attrs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.AppGroup.command"> <span class="sig-name descname"><span class="pre">command</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.AppGroup.command" title="Link to this definition">¶</a></dt> <dd><p>This works exactly like the method of the same name on a regular <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Group" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">click.Group</span></code></a> but it wraps callbacks in <a class="reference internal" href="#flask.cli.with_appcontext" title="flask.cli.with_appcontext"><code class="xref py py-func docutils literal notranslate"><span class="pre">with_appcontext()</span></code></a> unless it’s disabled by passing <code class="docutils literal notranslate"><span class="pre">with_appcontext=False</span></code>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[…], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]], <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Command" title="(in Click v8.1.x)"><em>Command</em></a>]</p> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.AppGroup.group"> <span class="sig-name descname"><span class="pre">group</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.AppGroup.group" title="Link to this definition">¶</a></dt> <dd><p>This works exactly like the method of the same name on a regular <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Group" title="(in Click v8.1.x)"><code class="xref py py-class docutils literal notranslate"><span class="pre">click.Group</span></code></a> but it defaults the group class to <a class="reference internal" href="#flask.cli.AppGroup" title="flask.cli.AppGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppGroup</span></code></a>.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Callable" title="(in Python v3.13)"><em>Callable</em></a>[[…], <a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>]], <a class="reference external" href="https://click.palletsprojects.com/en/stable/api/#click.Group" title="(in Click v8.1.x)"><em>Group</em></a>]</p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">ScriptInfo</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">app_import_path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">create_app</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">set_debug_flag</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_dotenv_defaults</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.ScriptInfo" title="Link to this definition">¶</a></dt> <dd><p>Helper object to deal with Flask applications. This is usually not necessary to interface with as it’s used internally in the dispatching to click. In future versions of Flask this object will most likely play a bigger role. Typically it’s created automatically by the <a class="reference internal" href="#flask.cli.FlaskGroup" title="flask.cli.FlaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlaskGroup</span></code></a> but you can also manually create it and pass it onwards as click object.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <code class="docutils literal notranslate"><span class="pre">load_dotenv_defaults</span></code> parameter and attribute.</p> </div> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>app_import_path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><em>None</em>)</p></li> <li><p><strong>create_app</strong> (<em>t.Callable</em><em>[</em><em>...</em><em>, </em><a class="reference internal" href="#flask.Flask" title="flask.Flask"><em>Flask</em></a><em>] </em><em>| </em><em>None</em>)</p></li> <li><p><strong>set_debug_flag</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> <li><p><strong>load_dotenv_defaults</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>)</p></li> </ul> </dd> </dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo.app_import_path"> <span class="sig-name descname"><span class="pre">app_import_path</span></span><a class="headerlink" href="#flask.cli.ScriptInfo.app_import_path" title="Link to this definition">¶</a></dt> <dd><p>Optionally the import path for the Flask application.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo.create_app"> <span class="sig-name descname"><span class="pre">create_app</span></span><a class="headerlink" href="#flask.cli.ScriptInfo.create_app" title="Link to this definition">¶</a></dt> <dd><p>Optionally a function that is passed the script info to create the instance of the application.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo.data"> <span class="sig-name descname"><span class="pre">data</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#dict" title="(in Python v3.13)"><span class="pre">dict</span></a><span class="p"><span class="pre">[</span></span><span class="pre">t.Any</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">t.Any</span><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#flask.cli.ScriptInfo.data" title="Link to this definition">¶</a></dt> <dd><p>A dictionary with arbitrary data that can be associated with this script info.</p> </dd></dl> <dl class="py attribute"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo.load_dotenv_defaults"> <span class="sig-name descname"><span class="pre">load_dotenv_defaults</span></span><a class="headerlink" href="#flask.cli.ScriptInfo.load_dotenv_defaults" title="Link to this definition">¶</a></dt> <dd><p>Whether default <code class="docutils literal notranslate"><span class="pre">.flaskenv</span></code> and <code class="docutils literal notranslate"><span class="pre">.env</span></code> files should be loaded.</p> <p><code class="docutils literal notranslate"><span class="pre">ScriptInfo</span></code> doesn’t load anything, this is for reference when doing the load elsewhere during processing.</p> <div class="versionadded"> <p><span class="versionmodified added">Added in version 3.1.</span></p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="flask.cli.ScriptInfo.load_app"> <span class="sig-name descname"><span class="pre">load_app</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.ScriptInfo.load_app" title="Link to this definition">¶</a></dt> <dd><p>Loads the Flask app (if not yet loaded) and returns it. Calling this multiple times will just result in the already loaded app to be returned.</p> <dl class="field-list simple"> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference internal" href="#flask.Flask" title="flask.Flask">Flask</a></p> </dd> </dl> </dd></dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.cli.load_dotenv"> <span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">load_dotenv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">load_defaults</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.load_dotenv" title="Link to this definition">¶</a></dt> <dd><p>Load “dotenv” files to set environment variables. A given path takes precedence over <code class="docutils literal notranslate"><span class="pre">.env</span></code>, which takes precedence over <code class="docutils literal notranslate"><span class="pre">.flaskenv</span></code>. After loading and combining these files, values are only set if the key is not already set in <code class="docutils literal notranslate"><span class="pre">os.environ</span></code>.</p> <p>This is a no-op if <a class="reference external" href="https://github.com/theskumar/python-dotenv#readme">python-dotenv</a> is not installed.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>path</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em> | </em><a class="reference external" href="https://docs.python.org/3/library/os.html#os.PathLike" title="(in Python v3.13)"><em>PathLike</em></a><em>[</em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.13)"><em>str</em></a><em>] </em><em>| </em><em>None</em>) – Load the file at this location.</p></li> <li><p><strong>load_defaults</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)"><em>bool</em></a>) – Search for and load the default <code class="docutils literal notranslate"><span class="pre">.flaskenv</span></code> and <code class="docutils literal notranslate"><span class="pre">.env</span></code> files.</p></li> </ul> </dd> <dt class="field-even">Returns<span class="colon">:</span></dt> <dd class="field-even"><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if at least one env var was loaded.</p> </dd> <dt class="field-odd">Return type<span class="colon">:</span></dt> <dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.13)">bool</a></p> </dd> </dl> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.1: </span>Added the <code class="docutils literal notranslate"><span class="pre">load_defaults</span></code> parameter. A given path takes precedence over default files.</p> </div> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>The current directory is not changed to the location of the loaded file.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.0: </span>When loading the env files, set the default encoding to UTF-8.</p> </div> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 1.1.0: </span>Returns <code class="docutils literal notranslate"><span class="pre">False</span></code> when python-dotenv is not installed, or when the given path isn’t a file.</p> </div> <div class="versionadded"> <p><span class="versionmodified added">Added in version 1.0.</span></p> </div> </details></dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.cli.with_appcontext"> <span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">with_appcontext</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.with_appcontext" title="Link to this definition">¶</a></dt> <dd><p>Wraps a callback so that it’s guaranteed to be executed with the script’s application context.</p> <p>Custom commands (and their options) registered under <code class="docutils literal notranslate"><span class="pre">app.cli</span></code> or <code class="docutils literal notranslate"><span class="pre">blueprint.cli</span></code> will always have an app context available, this decorator is not required in that case.</p> <details class="changelog"> <summary>Changelog</summary><div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 2.2: </span>The app context is active for subcommands as well as the decorated callback. The app context is always available to <code class="docutils literal notranslate"><span class="pre">app.cli</span></code> command and parameter callbacks.</p> </div> </details><dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>F</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><em>F</em></p> </dd> </dl> </dd></dl> <dl class="py function"> <dt class="sig sig-object py" id="flask.cli.pass_script_info"> <span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">pass_script_info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#flask.cli.pass_script_info" title="Link to this definition">¶</a></dt> <dd><p>Marks a function so that an instance of <a class="reference internal" href="#flask.cli.ScriptInfo" title="flask.cli.ScriptInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScriptInfo</span></code></a> is passed as first argument to the click callback.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><p><strong>f</strong> (<em>t.Callable</em><em>[</em><em>te.Concatenate</em><em>[</em><em>T</em><em>, </em><em>P</em><em>]</em><em>, </em><em>R</em><em>]</em>)</p> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p>t.Callable[P, R]</p> </dd> </dl> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.cli.run_command"> <span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">run_command</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">&lt;Command</span> <span class="pre">run&gt;</span></em><a class="headerlink" href="#flask.cli.run_command" title="Link to this definition">¶</a></dt> <dd><p>Run a local development server.</p> <p>This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers.</p> <p>The reloader and debugger are enabled by default with the ‘–debug’ option.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> <dl class="py data"> <dt class="sig sig-object py" id="flask.cli.shell_command"> <span class="sig-prename descclassname"><span class="pre">flask.cli.</span></span><span class="sig-name descname"><span class="pre">shell_command</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">&lt;Command</span> <span class="pre">shell&gt;</span></em><a class="headerlink" href="#flask.cli.shell_command" title="Link to this definition">¶</a></dt> <dd><p>Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration.</p> <p>This is useful for executing small snippets of management code without having to manually configure the application.</p> <dl class="field-list simple"> <dt class="field-odd">Parameters<span class="colon">:</span></dt> <dd class="field-odd"><ul class="simple"> <li><p><strong>args</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> <li><p><strong>kwargs</strong> (<a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a>)</p></li> </ul> </dd> <dt class="field-even">Return type<span class="colon">:</span></dt> <dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/typing.html#typing.Any" title="(in Python v3.13)"><em>Any</em></a></p> </dd> </dl> </dd></dl> </section> </section> <div class="clearer"></div> </div> </div> </div> <span id="sidebar-top"></span> <div class="sphinxsidebar" role="navigation" aria-label="Main"> <div class="sphinxsidebarwrapper"> <p class="logo"><a href="../"> <img class="logo" src="../_static/flask-vertical.png" alt="Logo of Flask"/> </a></p> <h3>Contents</h3> <ul> <li><a class="reference internal" href="#">API</a><ul> <li><a class="reference internal" href="#application-object">Application Object</a><ul> <li><a class="reference internal" href="#flask.Flask"><code class="docutils literal notranslate"><span class="pre">Flask</span></code></a><ul> <li><a class="reference internal" href="#flask.Flask.request_class"><code class="docutils literal notranslate"><span class="pre">Flask.request_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.response_class"><code class="docutils literal notranslate"><span class="pre">Flask.response_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.session_interface"><code class="docutils literal notranslate"><span class="pre">Flask.session_interface</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.cli"><code class="docutils literal notranslate"><span class="pre">Flask.cli</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.get_send_file_max_age"><code class="docutils literal notranslate"><span class="pre">Flask.get_send_file_max_age()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.send_static_file"><code class="docutils literal notranslate"><span class="pre">Flask.send_static_file()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.open_resource"><code class="docutils literal notranslate"><span class="pre">Flask.open_resource()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.open_instance_resource"><code class="docutils literal notranslate"><span class="pre">Flask.open_instance_resource()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.create_jinja_environment"><code class="docutils literal notranslate"><span class="pre">Flask.create_jinja_environment()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.create_url_adapter"><code class="docutils literal notranslate"><span class="pre">Flask.create_url_adapter()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.update_template_context"><code class="docutils literal notranslate"><span class="pre">Flask.update_template_context()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.make_shell_context"><code class="docutils literal notranslate"><span class="pre">Flask.make_shell_context()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.run"><code class="docutils literal notranslate"><span class="pre">Flask.run()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.test_client"><code class="docutils literal notranslate"><span class="pre">Flask.test_client()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.test_cli_runner"><code class="docutils literal notranslate"><span class="pre">Flask.test_cli_runner()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.handle_http_exception"><code class="docutils literal notranslate"><span class="pre">Flask.handle_http_exception()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.handle_user_exception"><code class="docutils literal notranslate"><span class="pre">Flask.handle_user_exception()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.handle_exception"><code class="docutils literal notranslate"><span class="pre">Flask.handle_exception()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.log_exception"><code class="docutils literal notranslate"><span class="pre">Flask.log_exception()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.dispatch_request"><code class="docutils literal notranslate"><span class="pre">Flask.dispatch_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.full_dispatch_request"><code class="docutils literal notranslate"><span class="pre">Flask.full_dispatch_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.make_default_options_response"><code class="docutils literal notranslate"><span class="pre">Flask.make_default_options_response()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.ensure_sync"><code class="docutils literal notranslate"><span class="pre">Flask.ensure_sync()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.async_to_sync"><code class="docutils literal notranslate"><span class="pre">Flask.async_to_sync()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_for"><code class="docutils literal notranslate"><span class="pre">Flask.url_for()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.make_response"><code class="docutils literal notranslate"><span class="pre">Flask.make_response()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.preprocess_request"><code class="docutils literal notranslate"><span class="pre">Flask.preprocess_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.process_response"><code class="docutils literal notranslate"><span class="pre">Flask.process_response()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.do_teardown_request"><code class="docutils literal notranslate"><span class="pre">Flask.do_teardown_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.do_teardown_appcontext"><code class="docutils literal notranslate"><span class="pre">Flask.do_teardown_appcontext()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.app_context"><code class="docutils literal notranslate"><span class="pre">Flask.app_context()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.request_context"><code class="docutils literal notranslate"><span class="pre">Flask.request_context()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.test_request_context"><code class="docutils literal notranslate"><span class="pre">Flask.test_request_context()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.wsgi_app"><code class="docutils literal notranslate"><span class="pre">Flask.wsgi_app()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.aborter_class"><code class="docutils literal notranslate"><span class="pre">Flask.aborter_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.add_template_filter"><code class="docutils literal notranslate"><span class="pre">Flask.add_template_filter()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.add_template_global"><code class="docutils literal notranslate"><span class="pre">Flask.add_template_global()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.add_template_test"><code class="docutils literal notranslate"><span class="pre">Flask.add_template_test()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.add_url_rule"><code class="docutils literal notranslate"><span class="pre">Flask.add_url_rule()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.after_request"><code class="docutils literal notranslate"><span class="pre">Flask.after_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.app_ctx_globals_class"><code class="docutils literal notranslate"><span class="pre">Flask.app_ctx_globals_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.auto_find_instance_path"><code class="docutils literal notranslate"><span class="pre">Flask.auto_find_instance_path()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.before_request"><code class="docutils literal notranslate"><span class="pre">Flask.before_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.config_class"><code class="docutils literal notranslate"><span class="pre">Flask.config_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.context_processor"><code class="docutils literal notranslate"><span class="pre">Flask.context_processor()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.create_global_jinja_loader"><code class="docutils literal notranslate"><span class="pre">Flask.create_global_jinja_loader()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.debug"><code class="docutils literal notranslate"><span class="pre">Flask.debug</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.delete"><code class="docutils literal notranslate"><span class="pre">Flask.delete()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.endpoint"><code class="docutils literal notranslate"><span class="pre">Flask.endpoint()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.errorhandler"><code class="docutils literal notranslate"><span class="pre">Flask.errorhandler()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.get"><code class="docutils literal notranslate"><span class="pre">Flask.get()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.handle_url_build_error"><code class="docutils literal notranslate"><span class="pre">Flask.handle_url_build_error()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.has_static_folder"><code class="docutils literal notranslate"><span class="pre">Flask.has_static_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.inject_url_defaults"><code class="docutils literal notranslate"><span class="pre">Flask.inject_url_defaults()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.iter_blueprints"><code class="docutils literal notranslate"><span class="pre">Flask.iter_blueprints()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.jinja_env"><code class="docutils literal notranslate"><span class="pre">Flask.jinja_env</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.jinja_environment"><code class="docutils literal notranslate"><span class="pre">Flask.jinja_environment</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.jinja_loader"><code class="docutils literal notranslate"><span class="pre">Flask.jinja_loader</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.jinja_options"><code class="docutils literal notranslate"><span class="pre">Flask.jinja_options</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.json_provider_class"><code class="docutils literal notranslate"><span class="pre">Flask.json_provider_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.logger"><code class="docutils literal notranslate"><span class="pre">Flask.logger</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.make_aborter"><code class="docutils literal notranslate"><span class="pre">Flask.make_aborter()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.make_config"><code class="docutils literal notranslate"><span class="pre">Flask.make_config()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.name"><code class="docutils literal notranslate"><span class="pre">Flask.name</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.patch"><code class="docutils literal notranslate"><span class="pre">Flask.patch()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.permanent_session_lifetime"><code class="docutils literal notranslate"><span class="pre">Flask.permanent_session_lifetime</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.post"><code class="docutils literal notranslate"><span class="pre">Flask.post()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.put"><code class="docutils literal notranslate"><span class="pre">Flask.put()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.redirect"><code class="docutils literal notranslate"><span class="pre">Flask.redirect()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.register_blueprint"><code class="docutils literal notranslate"><span class="pre">Flask.register_blueprint()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.register_error_handler"><code class="docutils literal notranslate"><span class="pre">Flask.register_error_handler()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.route"><code class="docutils literal notranslate"><span class="pre">Flask.route()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.secret_key"><code class="docutils literal notranslate"><span class="pre">Flask.secret_key</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.select_jinja_autoescape"><code class="docutils literal notranslate"><span class="pre">Flask.select_jinja_autoescape()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.shell_context_processor"><code class="docutils literal notranslate"><span class="pre">Flask.shell_context_processor()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.should_ignore_error"><code class="docutils literal notranslate"><span class="pre">Flask.should_ignore_error()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.static_folder"><code class="docutils literal notranslate"><span class="pre">Flask.static_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.static_url_path"><code class="docutils literal notranslate"><span class="pre">Flask.static_url_path</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.teardown_appcontext"><code class="docutils literal notranslate"><span class="pre">Flask.teardown_appcontext()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.teardown_request"><code class="docutils literal notranslate"><span class="pre">Flask.teardown_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.template_filter"><code class="docutils literal notranslate"><span class="pre">Flask.template_filter()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.template_global"><code class="docutils literal notranslate"><span class="pre">Flask.template_global()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.template_test"><code class="docutils literal notranslate"><span class="pre">Flask.template_test()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.test_cli_runner_class"><code class="docutils literal notranslate"><span class="pre">Flask.test_cli_runner_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.test_client_class"><code class="docutils literal notranslate"><span class="pre">Flask.test_client_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.testing"><code class="docutils literal notranslate"><span class="pre">Flask.testing</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.trap_http_exception"><code class="docutils literal notranslate"><span class="pre">Flask.trap_http_exception()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_defaults"><code class="docutils literal notranslate"><span class="pre">Flask.url_defaults()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_map_class"><code class="docutils literal notranslate"><span class="pre">Flask.url_map_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_rule_class"><code class="docutils literal notranslate"><span class="pre">Flask.url_rule_class</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_value_preprocessor"><code class="docutils literal notranslate"><span class="pre">Flask.url_value_preprocessor()</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.instance_path"><code class="docutils literal notranslate"><span class="pre">Flask.instance_path</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.config"><code class="docutils literal notranslate"><span class="pre">Flask.config</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.aborter"><code class="docutils literal notranslate"><span class="pre">Flask.aborter</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.json"><code class="docutils literal notranslate"><span class="pre">Flask.json</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_build_error_handlers"><code class="docutils literal notranslate"><span class="pre">Flask.url_build_error_handlers</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.teardown_appcontext_funcs"><code class="docutils literal notranslate"><span class="pre">Flask.teardown_appcontext_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.shell_context_processors"><code class="docutils literal notranslate"><span class="pre">Flask.shell_context_processors</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.blueprints"><code class="docutils literal notranslate"><span class="pre">Flask.blueprints</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.extensions"><code class="docutils literal notranslate"><span class="pre">Flask.extensions</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_map"><code class="docutils literal notranslate"><span class="pre">Flask.url_map</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.import_name"><code class="docutils literal notranslate"><span class="pre">Flask.import_name</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.template_folder"><code class="docutils literal notranslate"><span class="pre">Flask.template_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.root_path"><code class="docutils literal notranslate"><span class="pre">Flask.root_path</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.view_functions"><code class="docutils literal notranslate"><span class="pre">Flask.view_functions</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.error_handler_spec"><code class="docutils literal notranslate"><span class="pre">Flask.error_handler_spec</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.before_request_funcs"><code class="docutils literal notranslate"><span class="pre">Flask.before_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.after_request_funcs"><code class="docutils literal notranslate"><span class="pre">Flask.after_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.teardown_request_funcs"><code class="docutils literal notranslate"><span class="pre">Flask.teardown_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.template_context_processors"><code class="docutils literal notranslate"><span class="pre">Flask.template_context_processors</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_value_preprocessors"><code class="docutils literal notranslate"><span class="pre">Flask.url_value_preprocessors</span></code></a></li> <li><a class="reference internal" href="#flask.Flask.url_default_functions"><code class="docutils literal notranslate"><span class="pre">Flask.url_default_functions</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#blueprint-objects">Blueprint Objects</a><ul> <li><a class="reference internal" href="#flask.Blueprint"><code class="docutils literal notranslate"><span class="pre">Blueprint</span></code></a><ul> <li><a class="reference internal" href="#flask.Blueprint.cli"><code class="docutils literal notranslate"><span class="pre">Blueprint.cli</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.get_send_file_max_age"><code class="docutils literal notranslate"><span class="pre">Blueprint.get_send_file_max_age()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.send_static_file"><code class="docutils literal notranslate"><span class="pre">Blueprint.send_static_file()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.open_resource"><code class="docutils literal notranslate"><span class="pre">Blueprint.open_resource()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.add_app_template_filter"><code class="docutils literal notranslate"><span class="pre">Blueprint.add_app_template_filter()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.add_app_template_global"><code class="docutils literal notranslate"><span class="pre">Blueprint.add_app_template_global()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.add_app_template_test"><code class="docutils literal notranslate"><span class="pre">Blueprint.add_app_template_test()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.add_url_rule"><code class="docutils literal notranslate"><span class="pre">Blueprint.add_url_rule()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.after_app_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.after_app_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.after_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.after_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_context_processor"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_context_processor()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_errorhandler"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_errorhandler()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_template_filter"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_template_filter()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_template_global"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_template_global()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_template_test"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_template_test()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_url_defaults"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_url_defaults()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.app_url_value_preprocessor"><code class="docutils literal notranslate"><span class="pre">Blueprint.app_url_value_preprocessor()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.before_app_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.before_app_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.before_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.before_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.context_processor"><code class="docutils literal notranslate"><span class="pre">Blueprint.context_processor()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.delete"><code class="docutils literal notranslate"><span class="pre">Blueprint.delete()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.endpoint"><code class="docutils literal notranslate"><span class="pre">Blueprint.endpoint()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.errorhandler"><code class="docutils literal notranslate"><span class="pre">Blueprint.errorhandler()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.get"><code class="docutils literal notranslate"><span class="pre">Blueprint.get()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.has_static_folder"><code class="docutils literal notranslate"><span class="pre">Blueprint.has_static_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.jinja_loader"><code class="docutils literal notranslate"><span class="pre">Blueprint.jinja_loader</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.make_setup_state"><code class="docutils literal notranslate"><span class="pre">Blueprint.make_setup_state()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.patch"><code class="docutils literal notranslate"><span class="pre">Blueprint.patch()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.post"><code class="docutils literal notranslate"><span class="pre">Blueprint.post()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.put"><code class="docutils literal notranslate"><span class="pre">Blueprint.put()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.record"><code class="docutils literal notranslate"><span class="pre">Blueprint.record()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.record_once"><code class="docutils literal notranslate"><span class="pre">Blueprint.record_once()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.register"><code class="docutils literal notranslate"><span class="pre">Blueprint.register()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.register_blueprint"><code class="docutils literal notranslate"><span class="pre">Blueprint.register_blueprint()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.register_error_handler"><code class="docutils literal notranslate"><span class="pre">Blueprint.register_error_handler()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.route"><code class="docutils literal notranslate"><span class="pre">Blueprint.route()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.static_folder"><code class="docutils literal notranslate"><span class="pre">Blueprint.static_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.static_url_path"><code class="docutils literal notranslate"><span class="pre">Blueprint.static_url_path</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.teardown_app_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.teardown_app_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.teardown_request"><code class="docutils literal notranslate"><span class="pre">Blueprint.teardown_request()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.url_defaults"><code class="docutils literal notranslate"><span class="pre">Blueprint.url_defaults()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.url_value_preprocessor"><code class="docutils literal notranslate"><span class="pre">Blueprint.url_value_preprocessor()</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.import_name"><code class="docutils literal notranslate"><span class="pre">Blueprint.import_name</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.template_folder"><code class="docutils literal notranslate"><span class="pre">Blueprint.template_folder</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.root_path"><code class="docutils literal notranslate"><span class="pre">Blueprint.root_path</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.view_functions"><code class="docutils literal notranslate"><span class="pre">Blueprint.view_functions</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.error_handler_spec"><code class="docutils literal notranslate"><span class="pre">Blueprint.error_handler_spec</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.before_request_funcs"><code class="docutils literal notranslate"><span class="pre">Blueprint.before_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.after_request_funcs"><code class="docutils literal notranslate"><span class="pre">Blueprint.after_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.teardown_request_funcs"><code class="docutils literal notranslate"><span class="pre">Blueprint.teardown_request_funcs</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.template_context_processors"><code class="docutils literal notranslate"><span class="pre">Blueprint.template_context_processors</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.url_value_preprocessors"><code class="docutils literal notranslate"><span class="pre">Blueprint.url_value_preprocessors</span></code></a></li> <li><a class="reference internal" href="#flask.Blueprint.url_default_functions"><code class="docutils literal notranslate"><span class="pre">Blueprint.url_default_functions</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#incoming-request-data">Incoming Request Data</a><ul> <li><a class="reference internal" href="#flask.Request"><code class="docutils literal notranslate"><span class="pre">Request</span></code></a><ul> <li><a class="reference internal" href="#flask.Request.url_rule"><code class="docutils literal notranslate"><span class="pre">Request.url_rule</span></code></a></li> <li><a class="reference internal" href="#flask.Request.view_args"><code class="docutils literal notranslate"><span class="pre">Request.view_args</span></code></a></li> <li><a class="reference internal" href="#flask.Request.routing_exception"><code class="docutils literal notranslate"><span class="pre">Request.routing_exception</span></code></a></li> <li><a class="reference internal" href="#flask.Request.max_content_length"><code class="docutils literal notranslate"><span class="pre">Request.max_content_length</span></code></a></li> <li><a class="reference internal" href="#flask.Request.max_form_memory_size"><code class="docutils literal notranslate"><span class="pre">Request.max_form_memory_size</span></code></a></li> <li><a class="reference internal" href="#flask.Request.max_form_parts"><code class="docutils literal notranslate"><span class="pre">Request.max_form_parts</span></code></a></li> <li><a class="reference internal" href="#flask.Request.endpoint"><code class="docutils literal notranslate"><span class="pre">Request.endpoint</span></code></a></li> <li><a class="reference internal" href="#flask.Request.blueprint"><code class="docutils literal notranslate"><span class="pre">Request.blueprint</span></code></a></li> <li><a class="reference internal" href="#flask.Request.blueprints"><code class="docutils literal notranslate"><span class="pre">Request.blueprints</span></code></a></li> <li><a class="reference internal" href="#flask.Request.on_json_loading_failed"><code class="docutils literal notranslate"><span class="pre">Request.on_json_loading_failed()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.accept_charsets"><code class="docutils literal notranslate"><span class="pre">Request.accept_charsets</span></code></a></li> <li><a class="reference internal" href="#flask.Request.accept_encodings"><code class="docutils literal notranslate"><span class="pre">Request.accept_encodings</span></code></a></li> <li><a class="reference internal" href="#flask.Request.accept_languages"><code class="docutils literal notranslate"><span class="pre">Request.accept_languages</span></code></a></li> <li><a class="reference internal" href="#flask.Request.accept_mimetypes"><code class="docutils literal notranslate"><span class="pre">Request.accept_mimetypes</span></code></a></li> <li><a class="reference internal" href="#flask.Request.access_control_request_headers"><code class="docutils literal notranslate"><span class="pre">Request.access_control_request_headers</span></code></a></li> <li><a class="reference internal" href="#flask.Request.access_control_request_method"><code class="docutils literal notranslate"><span class="pre">Request.access_control_request_method</span></code></a></li> <li><a class="reference internal" href="#flask.Request.access_route"><code class="docutils literal notranslate"><span class="pre">Request.access_route</span></code></a></li> <li><a class="reference internal" href="#flask.Request.application"><code class="docutils literal notranslate"><span class="pre">Request.application()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.args"><code class="docutils literal notranslate"><span class="pre">Request.args</span></code></a></li> <li><a class="reference internal" href="#flask.Request.authorization"><code class="docutils literal notranslate"><span class="pre">Request.authorization</span></code></a></li> <li><a class="reference internal" href="#flask.Request.base_url"><code class="docutils literal notranslate"><span class="pre">Request.base_url</span></code></a></li> <li><a class="reference internal" href="#flask.Request.cache_control"><code class="docutils literal notranslate"><span class="pre">Request.cache_control</span></code></a></li> <li><a class="reference internal" href="#flask.Request.close"><code class="docutils literal notranslate"><span class="pre">Request.close()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.content_encoding"><code class="docutils literal notranslate"><span class="pre">Request.content_encoding</span></code></a></li> <li><a class="reference internal" href="#flask.Request.content_length"><code class="docutils literal notranslate"><span class="pre">Request.content_length</span></code></a></li> <li><a class="reference internal" href="#flask.Request.content_md5"><code class="docutils literal notranslate"><span class="pre">Request.content_md5</span></code></a></li> <li><a class="reference internal" href="#flask.Request.content_type"><code class="docutils literal notranslate"><span class="pre">Request.content_type</span></code></a></li> <li><a class="reference internal" href="#flask.Request.cookies"><code class="docutils literal notranslate"><span class="pre">Request.cookies</span></code></a></li> <li><a class="reference internal" href="#flask.Request.data"><code class="docutils literal notranslate"><span class="pre">Request.data</span></code></a></li> <li><a class="reference internal" href="#flask.Request.date"><code class="docutils literal notranslate"><span class="pre">Request.date</span></code></a></li> <li><a class="reference internal" href="#flask.Request.dict_storage_class"><code class="docutils literal notranslate"><span class="pre">Request.dict_storage_class</span></code></a></li> <li><a class="reference internal" href="#flask.Request.files"><code class="docutils literal notranslate"><span class="pre">Request.files</span></code></a></li> <li><a class="reference internal" href="#flask.Request.form"><code class="docutils literal notranslate"><span class="pre">Request.form</span></code></a></li> <li><a class="reference internal" href="#flask.Request.form_data_parser_class"><code class="docutils literal notranslate"><span class="pre">Request.form_data_parser_class</span></code></a></li> <li><a class="reference internal" href="#flask.Request.from_values"><code class="docutils literal notranslate"><span class="pre">Request.from_values()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.full_path"><code class="docutils literal notranslate"><span class="pre">Request.full_path</span></code></a></li> <li><a class="reference internal" href="#flask.Request.get_data"><code class="docutils literal notranslate"><span class="pre">Request.get_data()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.get_json"><code class="docutils literal notranslate"><span class="pre">Request.get_json()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.host"><code class="docutils literal notranslate"><span class="pre">Request.host</span></code></a></li> <li><a class="reference internal" href="#flask.Request.host_url"><code class="docutils literal notranslate"><span class="pre">Request.host_url</span></code></a></li> <li><a class="reference internal" href="#flask.Request.if_match"><code class="docutils literal notranslate"><span class="pre">Request.if_match</span></code></a></li> <li><a class="reference internal" href="#flask.Request.if_modified_since"><code class="docutils literal notranslate"><span class="pre">Request.if_modified_since</span></code></a></li> <li><a class="reference internal" href="#flask.Request.if_none_match"><code class="docutils literal notranslate"><span class="pre">Request.if_none_match</span></code></a></li> <li><a class="reference internal" href="#flask.Request.if_range"><code class="docutils literal notranslate"><span class="pre">Request.if_range</span></code></a></li> <li><a class="reference internal" href="#flask.Request.if_unmodified_since"><code class="docutils literal notranslate"><span class="pre">Request.if_unmodified_since</span></code></a></li> <li><a class="reference internal" href="#flask.Request.input_stream"><code class="docutils literal notranslate"><span class="pre">Request.input_stream</span></code></a></li> <li><a class="reference internal" href="#flask.Request.is_json"><code class="docutils literal notranslate"><span class="pre">Request.is_json</span></code></a></li> <li><a class="reference internal" href="#flask.Request.is_multiprocess"><code class="docutils literal notranslate"><span class="pre">Request.is_multiprocess</span></code></a></li> <li><a class="reference internal" href="#flask.Request.is_multithread"><code class="docutils literal notranslate"><span class="pre">Request.is_multithread</span></code></a></li> <li><a class="reference internal" href="#flask.Request.is_run_once"><code class="docutils literal notranslate"><span class="pre">Request.is_run_once</span></code></a></li> <li><a class="reference internal" href="#flask.Request.is_secure"><code class="docutils literal notranslate"><span class="pre">Request.is_secure</span></code></a></li> <li><a class="reference internal" href="#flask.Request.json"><code class="docutils literal notranslate"><span class="pre">Request.json</span></code></a></li> <li><a class="reference internal" href="#flask.Request.list_storage_class"><code class="docutils literal notranslate"><span class="pre">Request.list_storage_class</span></code></a></li> <li><a class="reference internal" href="#flask.Request.make_form_data_parser"><code class="docutils literal notranslate"><span class="pre">Request.make_form_data_parser()</span></code></a></li> <li><a class="reference internal" href="#flask.Request.max_forwards"><code class="docutils literal notranslate"><span class="pre">Request.max_forwards</span></code></a></li> <li><a class="reference internal" href="#flask.Request.mimetype"><code class="docutils literal notranslate"><span class="pre">Request.mimetype</span></code></a></li> <li><a class="reference internal" href="#flask.Request.mimetype_params"><code class="docutils literal notranslate"><span class="pre">Request.mimetype_params</span></code></a></li> <li><a class="reference internal" href="#flask.Request.origin"><code class="docutils literal notranslate"><span class="pre">Request.origin</span></code></a></li> <li><a class="reference internal" href="#flask.Request.parameter_storage_class"><code class="docutils literal notranslate"><span class="pre">Request.parameter_storage_class</span></code></a></li> <li><a class="reference internal" href="#flask.Request.pragma"><code class="docutils literal notranslate"><span class="pre">Request.pragma</span></code></a></li> <li><a class="reference internal" href="#flask.Request.range"><code class="docutils literal notranslate"><span class="pre">Request.range</span></code></a></li> <li><a class="reference internal" href="#flask.Request.referrer"><code class="docutils literal notranslate"><span class="pre">Request.referrer</span></code></a></li> <li><a class="reference internal" href="#flask.Request.remote_user"><code class="docutils literal notranslate"><span class="pre">Request.remote_user</span></code></a></li> <li><a class="reference internal" href="#flask.Request.root_url"><code class="docutils literal notranslate"><span class="pre">Request.root_url</span></code></a></li> <li><a class="reference internal" href="#flask.Request.script_root"><code class="docutils literal notranslate"><span class="pre">Request.script_root</span></code></a></li> <li><a class="reference internal" href="#flask.Request.stream"><code class="docutils literal notranslate"><span class="pre">Request.stream</span></code></a></li> <li><a class="reference internal" href="#flask.Request.trusted_hosts"><code class="docutils literal notranslate"><span class="pre">Request.trusted_hosts</span></code></a></li> <li><a class="reference internal" href="#flask.Request.url"><code class="docutils literal notranslate"><span class="pre">Request.url</span></code></a></li> <li><a class="reference internal" href="#flask.Request.url_root"><code class="docutils literal notranslate"><span class="pre">Request.url_root</span></code></a></li> <li><a class="reference internal" href="#flask.Request.user_agent"><code class="docutils literal notranslate"><span class="pre">Request.user_agent</span></code></a></li> <li><a class="reference internal" href="#flask.Request.user_agent_class"><code class="docutils literal notranslate"><span class="pre">Request.user_agent_class</span></code></a></li> <li><a class="reference internal" href="#flask.Request.values"><code class="docutils literal notranslate"><span class="pre">Request.values</span></code></a></li> <li><a class="reference internal" href="#flask.Request.want_form_data_parsed"><code class="docutils literal notranslate"><span class="pre">Request.want_form_data_parsed</span></code></a></li> <li><a class="reference internal" href="#flask.Request.environ"><code class="docutils literal notranslate"><span class="pre">Request.environ</span></code></a></li> <li><a class="reference internal" href="#flask.Request.shallow"><code class="docutils literal notranslate"><span class="pre">Request.shallow</span></code></a></li> <li><a class="reference internal" href="#flask.Request.method"><code class="docutils literal notranslate"><span class="pre">Request.method</span></code></a></li> <li><a class="reference internal" href="#flask.Request.scheme"><code class="docutils literal notranslate"><span class="pre">Request.scheme</span></code></a></li> <li><a class="reference internal" href="#flask.Request.server"><code class="docutils literal notranslate"><span class="pre">Request.server</span></code></a></li> <li><a class="reference internal" href="#flask.Request.root_path"><code class="docutils literal notranslate"><span class="pre">Request.root_path</span></code></a></li> <li><a class="reference internal" href="#flask.Request.path"><code class="docutils literal notranslate"><span class="pre">Request.path</span></code></a></li> <li><a class="reference internal" href="#flask.Request.query_string"><code class="docutils literal notranslate"><span class="pre">Request.query_string</span></code></a></li> <li><a class="reference internal" href="#flask.Request.headers"><code class="docutils literal notranslate"><span class="pre">Request.headers</span></code></a></li> <li><a class="reference internal" href="#flask.Request.remote_addr"><code class="docutils literal notranslate"><span class="pre">Request.remote_addr</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.request"><code class="docutils literal notranslate"><span class="pre">request</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#response-objects">Response Objects</a><ul> <li><a class="reference internal" href="#flask.Response"><code class="docutils literal notranslate"><span class="pre">Response</span></code></a><ul> <li><a class="reference internal" href="#flask.Response.default_mimetype"><code class="docutils literal notranslate"><span class="pre">Response.default_mimetype</span></code></a></li> <li><a class="reference internal" href="#flask.Response.accept_ranges"><code class="docutils literal notranslate"><span class="pre">Response.accept_ranges</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_allow_credentials"><code class="docutils literal notranslate"><span class="pre">Response.access_control_allow_credentials</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_allow_headers"><code class="docutils literal notranslate"><span class="pre">Response.access_control_allow_headers</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_allow_methods"><code class="docutils literal notranslate"><span class="pre">Response.access_control_allow_methods</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_allow_origin"><code class="docutils literal notranslate"><span class="pre">Response.access_control_allow_origin</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_expose_headers"><code class="docutils literal notranslate"><span class="pre">Response.access_control_expose_headers</span></code></a></li> <li><a class="reference internal" href="#flask.Response.access_control_max_age"><code class="docutils literal notranslate"><span class="pre">Response.access_control_max_age</span></code></a></li> <li><a class="reference internal" href="#flask.Response.add_etag"><code class="docutils literal notranslate"><span class="pre">Response.add_etag()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.age"><code class="docutils literal notranslate"><span class="pre">Response.age</span></code></a></li> <li><a class="reference internal" href="#flask.Response.allow"><code class="docutils literal notranslate"><span class="pre">Response.allow</span></code></a></li> <li><a class="reference internal" href="#flask.Response.automatically_set_content_length"><code class="docutils literal notranslate"><span class="pre">Response.automatically_set_content_length</span></code></a></li> <li><a class="reference internal" href="#flask.Response.cache_control"><code class="docutils literal notranslate"><span class="pre">Response.cache_control</span></code></a></li> <li><a class="reference internal" href="#flask.Response.calculate_content_length"><code class="docutils literal notranslate"><span class="pre">Response.calculate_content_length()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.call_on_close"><code class="docutils literal notranslate"><span class="pre">Response.call_on_close()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.close"><code class="docutils literal notranslate"><span class="pre">Response.close()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_encoding"><code class="docutils literal notranslate"><span class="pre">Response.content_encoding</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_language"><code class="docutils literal notranslate"><span class="pre">Response.content_language</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_length"><code class="docutils literal notranslate"><span class="pre">Response.content_length</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_location"><code class="docutils literal notranslate"><span class="pre">Response.content_location</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_md5"><code class="docutils literal notranslate"><span class="pre">Response.content_md5</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_range"><code class="docutils literal notranslate"><span class="pre">Response.content_range</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_security_policy"><code class="docutils literal notranslate"><span class="pre">Response.content_security_policy</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_security_policy_report_only"><code class="docutils literal notranslate"><span class="pre">Response.content_security_policy_report_only</span></code></a></li> <li><a class="reference internal" href="#flask.Response.content_type"><code class="docutils literal notranslate"><span class="pre">Response.content_type</span></code></a></li> <li><a class="reference internal" href="#flask.Response.cross_origin_embedder_policy"><code class="docutils literal notranslate"><span class="pre">Response.cross_origin_embedder_policy</span></code></a></li> <li><a class="reference internal" href="#flask.Response.cross_origin_opener_policy"><code class="docutils literal notranslate"><span class="pre">Response.cross_origin_opener_policy</span></code></a></li> <li><a class="reference internal" href="#flask.Response.data"><code class="docutils literal notranslate"><span class="pre">Response.data</span></code></a></li> <li><a class="reference internal" href="#flask.Response.date"><code class="docutils literal notranslate"><span class="pre">Response.date</span></code></a></li> <li><a class="reference internal" href="#flask.Response.default_status"><code class="docutils literal notranslate"><span class="pre">Response.default_status</span></code></a></li> <li><a class="reference internal" href="#flask.Response.delete_cookie"><code class="docutils literal notranslate"><span class="pre">Response.delete_cookie()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.expires"><code class="docutils literal notranslate"><span class="pre">Response.expires</span></code></a></li> <li><a class="reference internal" href="#flask.Response.force_type"><code class="docutils literal notranslate"><span class="pre">Response.force_type()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.freeze"><code class="docutils literal notranslate"><span class="pre">Response.freeze()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.from_app"><code class="docutils literal notranslate"><span class="pre">Response.from_app()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_app_iter"><code class="docutils literal notranslate"><span class="pre">Response.get_app_iter()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_data"><code class="docutils literal notranslate"><span class="pre">Response.get_data()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_etag"><code class="docutils literal notranslate"><span class="pre">Response.get_etag()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_json"><code class="docutils literal notranslate"><span class="pre">Response.get_json()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_wsgi_headers"><code class="docutils literal notranslate"><span class="pre">Response.get_wsgi_headers()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.get_wsgi_response"><code class="docutils literal notranslate"><span class="pre">Response.get_wsgi_response()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.implicit_sequence_conversion"><code class="docutils literal notranslate"><span class="pre">Response.implicit_sequence_conversion</span></code></a></li> <li><a class="reference internal" href="#flask.Response.is_json"><code class="docutils literal notranslate"><span class="pre">Response.is_json</span></code></a></li> <li><a class="reference internal" href="#flask.Response.is_sequence"><code class="docutils literal notranslate"><span class="pre">Response.is_sequence</span></code></a></li> <li><a class="reference internal" href="#flask.Response.is_streamed"><code class="docutils literal notranslate"><span class="pre">Response.is_streamed</span></code></a></li> <li><a class="reference internal" href="#flask.Response.iter_encoded"><code class="docutils literal notranslate"><span class="pre">Response.iter_encoded()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.json"><code class="docutils literal notranslate"><span class="pre">Response.json</span></code></a></li> <li><a class="reference internal" href="#flask.Response.last_modified"><code class="docutils literal notranslate"><span class="pre">Response.last_modified</span></code></a></li> <li><a class="reference internal" href="#flask.Response.location"><code class="docutils literal notranslate"><span class="pre">Response.location</span></code></a></li> <li><a class="reference internal" href="#flask.Response.make_conditional"><code class="docutils literal notranslate"><span class="pre">Response.make_conditional()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.make_sequence"><code class="docutils literal notranslate"><span class="pre">Response.make_sequence()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.mimetype"><code class="docutils literal notranslate"><span class="pre">Response.mimetype</span></code></a></li> <li><a class="reference internal" href="#flask.Response.mimetype_params"><code class="docutils literal notranslate"><span class="pre">Response.mimetype_params</span></code></a></li> <li><a class="reference internal" href="#flask.Response.retry_after"><code class="docutils literal notranslate"><span class="pre">Response.retry_after</span></code></a></li> <li><a class="reference internal" href="#flask.Response.set_cookie"><code class="docutils literal notranslate"><span class="pre">Response.set_cookie()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.set_data"><code class="docutils literal notranslate"><span class="pre">Response.set_data()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.set_etag"><code class="docutils literal notranslate"><span class="pre">Response.set_etag()</span></code></a></li> <li><a class="reference internal" href="#flask.Response.status"><code class="docutils literal notranslate"><span class="pre">Response.status</span></code></a></li> <li><a class="reference internal" href="#flask.Response.status_code"><code class="docutils literal notranslate"><span class="pre">Response.status_code</span></code></a></li> <li><a class="reference internal" href="#flask.Response.stream"><code class="docutils literal notranslate"><span class="pre">Response.stream</span></code></a></li> <li><a class="reference internal" href="#flask.Response.vary"><code class="docutils literal notranslate"><span class="pre">Response.vary</span></code></a></li> <li><a class="reference internal" href="#flask.Response.www_authenticate"><code class="docutils literal notranslate"><span class="pre">Response.www_authenticate</span></code></a></li> <li><a class="reference internal" href="#flask.Response.response"><code class="docutils literal notranslate"><span class="pre">Response.response</span></code></a></li> <li><a class="reference internal" href="#flask.Response.direct_passthrough"><code class="docutils literal notranslate"><span class="pre">Response.direct_passthrough</span></code></a></li> <li><a class="reference internal" href="#flask.Response.autocorrect_location_header"><code class="docutils literal notranslate"><span class="pre">Response.autocorrect_location_header</span></code></a></li> <li><a class="reference internal" href="#flask.Response.max_cookie_size"><code class="docutils literal notranslate"><span class="pre">Response.max_cookie_size</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#sessions">Sessions</a><ul> <li><a class="reference internal" href="#flask.session"><code class="docutils literal notranslate"><span class="pre">session</span></code></a><ul> <li><a class="reference internal" href="#flask.session.new"><code class="docutils literal notranslate"><span class="pre">session.new</span></code></a></li> <li><a class="reference internal" href="#flask.session.modified"><code class="docutils literal notranslate"><span class="pre">session.modified</span></code></a></li> <li><a class="reference internal" href="#flask.session.permanent"><code class="docutils literal notranslate"><span class="pre">session.permanent</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#session-interface">Session Interface</a><ul> <li><a class="reference internal" href="#flask.sessions.SessionInterface"><code class="docutils literal notranslate"><span class="pre">SessionInterface</span></code></a><ul> <li><a class="reference internal" href="#flask.sessions.SessionInterface.null_session_class"><code class="docutils literal notranslate"><span class="pre">SessionInterface.null_session_class</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.pickle_based"><code class="docutils literal notranslate"><span class="pre">SessionInterface.pickle_based</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.make_null_session"><code class="docutils literal notranslate"><span class="pre">SessionInterface.make_null_session()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.is_null_session"><code class="docutils literal notranslate"><span class="pre">SessionInterface.is_null_session()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_name"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_name()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_domain"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_domain()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_path"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_path()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_httponly"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_httponly()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_secure"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_secure()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_samesite"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_samesite()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_cookie_partitioned"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_cookie_partitioned()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.get_expiration_time"><code class="docutils literal notranslate"><span class="pre">SessionInterface.get_expiration_time()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.should_set_cookie"><code class="docutils literal notranslate"><span class="pre">SessionInterface.should_set_cookie()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.open_session"><code class="docutils literal notranslate"><span class="pre">SessionInterface.open_session()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionInterface.save_session"><code class="docutils literal notranslate"><span class="pre">SessionInterface.save_session()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface</span></code></a><ul> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.salt"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.salt</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.digest_method"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.digest_method()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.key_derivation"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.key_derivation</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.serializer"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.serializer</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.session_class"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.session_class</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.open_session"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.open_session()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSessionInterface.save_session"><code class="docutils literal notranslate"><span class="pre">SecureCookieSessionInterface.save_session()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSession"><code class="docutils literal notranslate"><span class="pre">SecureCookieSession</span></code></a><ul> <li><a class="reference internal" href="#flask.sessions.SecureCookieSession.modified"><code class="docutils literal notranslate"><span class="pre">SecureCookieSession.modified</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSession.accessed"><code class="docutils literal notranslate"><span class="pre">SecureCookieSession.accessed</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSession.get"><code class="docutils literal notranslate"><span class="pre">SecureCookieSession.get()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SecureCookieSession.setdefault"><code class="docutils literal notranslate"><span class="pre">SecureCookieSession.setdefault()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.sessions.NullSession"><code class="docutils literal notranslate"><span class="pre">NullSession</span></code></a><ul> <li><a class="reference internal" href="#flask.sessions.NullSession.clear"><code class="docutils literal notranslate"><span class="pre">NullSession.clear()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.NullSession.pop"><code class="docutils literal notranslate"><span class="pre">NullSession.pop()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.NullSession.popitem"><code class="docutils literal notranslate"><span class="pre">NullSession.popitem()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.NullSession.update"><code class="docutils literal notranslate"><span class="pre">NullSession.update()</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.NullSession.setdefault"><code class="docutils literal notranslate"><span class="pre">NullSession.setdefault()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.sessions.SessionMixin"><code class="docutils literal notranslate"><span class="pre">SessionMixin</span></code></a><ul> <li><a class="reference internal" href="#flask.sessions.SessionMixin.permanent"><code class="docutils literal notranslate"><span class="pre">SessionMixin.permanent</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionMixin.modified"><code class="docutils literal notranslate"><span class="pre">SessionMixin.modified</span></code></a></li> <li><a class="reference internal" href="#flask.sessions.SessionMixin.accessed"><code class="docutils literal notranslate"><span class="pre">SessionMixin.accessed</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#test-client">Test Client</a><ul> <li><a class="reference internal" href="#flask.testing.FlaskClient"><code class="docutils literal notranslate"><span class="pre">FlaskClient</span></code></a><ul> <li><a class="reference internal" href="#flask.testing.FlaskClient.session_transaction"><code class="docutils literal notranslate"><span class="pre">FlaskClient.session_transaction()</span></code></a></li> <li><a class="reference internal" href="#flask.testing.FlaskClient.open"><code class="docutils literal notranslate"><span class="pre">FlaskClient.open()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#test-cli-runner">Test CLI Runner</a><ul> <li><a class="reference internal" href="#flask.testing.FlaskCliRunner"><code class="docutils literal notranslate"><span class="pre">FlaskCliRunner</span></code></a><ul> <li><a class="reference internal" href="#flask.testing.FlaskCliRunner.invoke"><code class="docutils literal notranslate"><span class="pre">FlaskCliRunner.invoke()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#application-globals">Application Globals</a><ul> <li><a class="reference internal" href="#flask.g"><code class="docutils literal notranslate"><span class="pre">g</span></code></a></li> <li><a class="reference internal" href="#flask.ctx._AppCtxGlobals"><code class="docutils literal notranslate"><span class="pre">_AppCtxGlobals</span></code></a><ul> <li><a class="reference internal" href="#flask.ctx._AppCtxGlobals.get"><code class="docutils literal notranslate"><span class="pre">_AppCtxGlobals.get()</span></code></a></li> <li><a class="reference internal" href="#flask.ctx._AppCtxGlobals.pop"><code class="docutils literal notranslate"><span class="pre">_AppCtxGlobals.pop()</span></code></a></li> <li><a class="reference internal" href="#flask.ctx._AppCtxGlobals.setdefault"><code class="docutils literal notranslate"><span class="pre">_AppCtxGlobals.setdefault()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#useful-functions-and-classes">Useful Functions and Classes</a><ul> <li><a class="reference internal" href="#flask.current_app"><code class="docutils literal notranslate"><span class="pre">current_app</span></code></a></li> <li><a class="reference internal" href="#flask.has_request_context"><code class="docutils literal notranslate"><span class="pre">has_request_context()</span></code></a></li> <li><a class="reference internal" href="#flask.copy_current_request_context"><code class="docutils literal notranslate"><span class="pre">copy_current_request_context()</span></code></a></li> <li><a class="reference internal" href="#flask.has_app_context"><code class="docutils literal notranslate"><span class="pre">has_app_context()</span></code></a></li> <li><a class="reference internal" href="#flask.url_for"><code class="docutils literal notranslate"><span class="pre">url_for()</span></code></a></li> <li><a class="reference internal" href="#flask.abort"><code class="docutils literal notranslate"><span class="pre">abort()</span></code></a></li> <li><a class="reference internal" href="#flask.redirect"><code class="docutils literal notranslate"><span class="pre">redirect()</span></code></a></li> <li><a class="reference internal" href="#flask.make_response"><code class="docutils literal notranslate"><span class="pre">make_response()</span></code></a></li> <li><a class="reference internal" href="#flask.after_this_request"><code class="docutils literal notranslate"><span class="pre">after_this_request()</span></code></a></li> <li><a class="reference internal" href="#flask.send_file"><code class="docutils literal notranslate"><span class="pre">send_file()</span></code></a></li> <li><a class="reference internal" href="#flask.send_from_directory"><code class="docutils literal notranslate"><span class="pre">send_from_directory()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#message-flashing">Message Flashing</a><ul> <li><a class="reference internal" href="#flask.flash"><code class="docutils literal notranslate"><span class="pre">flash()</span></code></a></li> <li><a class="reference internal" href="#flask.get_flashed_messages"><code class="docutils literal notranslate"><span class="pre">get_flashed_messages()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#module-flask.json">JSON Support</a><ul> <li><a class="reference internal" href="#flask.json.jsonify"><code class="docutils literal notranslate"><span class="pre">jsonify()</span></code></a></li> <li><a class="reference internal" href="#flask.json.dumps"><code class="docutils literal notranslate"><span class="pre">dumps()</span></code></a></li> <li><a class="reference internal" href="#flask.json.dump"><code class="docutils literal notranslate"><span class="pre">dump()</span></code></a></li> <li><a class="reference internal" href="#flask.json.loads"><code class="docutils literal notranslate"><span class="pre">loads()</span></code></a></li> <li><a class="reference internal" href="#flask.json.load"><code class="docutils literal notranslate"><span class="pre">load()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.JSONProvider"><code class="docutils literal notranslate"><span class="pre">JSONProvider</span></code></a><ul> <li><a class="reference internal" href="#flask.json.provider.JSONProvider.dumps"><code class="docutils literal notranslate"><span class="pre">JSONProvider.dumps()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.JSONProvider.dump"><code class="docutils literal notranslate"><span class="pre">JSONProvider.dump()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.JSONProvider.loads"><code class="docutils literal notranslate"><span class="pre">JSONProvider.loads()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.JSONProvider.load"><code class="docutils literal notranslate"><span class="pre">JSONProvider.load()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.JSONProvider.response"><code class="docutils literal notranslate"><span class="pre">JSONProvider.response()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider</span></code></a><ul> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.default"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.default()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.ensure_ascii"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.ensure_ascii</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.sort_keys"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.sort_keys</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.compact"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.compact</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.mimetype"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.mimetype</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.dumps"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.dumps()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.loads"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.loads()</span></code></a></li> <li><a class="reference internal" href="#flask.json.provider.DefaultJSONProvider.response"><code class="docutils literal notranslate"><span class="pre">DefaultJSONProvider.response()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#tagged-json">Tagged JSON</a><ul> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer</span></code></a><ul> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.default_tags"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.default_tags</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.register"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.register()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.tag"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.tag()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.untag"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.untag()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.dumps"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.dumps()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.TaggedJSONSerializer.loads"><code class="docutils literal notranslate"><span class="pre">TaggedJSONSerializer.loads()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.json.tag.JSONTag"><code class="docutils literal notranslate"><span class="pre">JSONTag</span></code></a><ul> <li><a class="reference internal" href="#flask.json.tag.JSONTag.key"><code class="docutils literal notranslate"><span class="pre">JSONTag.key</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.JSONTag.check"><code class="docutils literal notranslate"><span class="pre">JSONTag.check()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.JSONTag.to_json"><code class="docutils literal notranslate"><span class="pre">JSONTag.to_json()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.JSONTag.to_python"><code class="docutils literal notranslate"><span class="pre">JSONTag.to_python()</span></code></a></li> <li><a class="reference internal" href="#flask.json.tag.JSONTag.tag"><code class="docutils literal notranslate"><span class="pre">JSONTag.tag()</span></code></a></li> </ul> </li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#template-rendering">Template Rendering</a><ul> <li><a class="reference internal" href="#flask.render_template"><code class="docutils literal notranslate"><span class="pre">render_template()</span></code></a></li> <li><a class="reference internal" href="#flask.render_template_string"><code class="docutils literal notranslate"><span class="pre">render_template_string()</span></code></a></li> <li><a class="reference internal" href="#flask.stream_template"><code class="docutils literal notranslate"><span class="pre">stream_template()</span></code></a></li> <li><a class="reference internal" href="#flask.stream_template_string"><code class="docutils literal notranslate"><span class="pre">stream_template_string()</span></code></a></li> <li><a class="reference internal" href="#flask.get_template_attribute"><code class="docutils literal notranslate"><span class="pre">get_template_attribute()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#configuration">Configuration</a><ul> <li><a class="reference internal" href="#flask.Config"><code class="docutils literal notranslate"><span class="pre">Config</span></code></a><ul> <li><a class="reference internal" href="#flask.Config.from_envvar"><code class="docutils literal notranslate"><span class="pre">Config.from_envvar()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.from_prefixed_env"><code class="docutils literal notranslate"><span class="pre">Config.from_prefixed_env()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.from_pyfile"><code class="docutils literal notranslate"><span class="pre">Config.from_pyfile()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.from_object"><code class="docutils literal notranslate"><span class="pre">Config.from_object()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.from_file"><code class="docutils literal notranslate"><span class="pre">Config.from_file()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.from_mapping"><code class="docutils literal notranslate"><span class="pre">Config.from_mapping()</span></code></a></li> <li><a class="reference internal" href="#flask.Config.get_namespace"><code class="docutils literal notranslate"><span class="pre">Config.get_namespace()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#stream-helpers">Stream Helpers</a><ul> <li><a class="reference internal" href="#flask.stream_with_context"><code class="docutils literal notranslate"><span class="pre">stream_with_context()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#useful-internals">Useful Internals</a><ul> <li><a class="reference internal" href="#flask.ctx.RequestContext"><code class="docutils literal notranslate"><span class="pre">RequestContext</span></code></a><ul> <li><a class="reference internal" href="#flask.ctx.RequestContext.copy"><code class="docutils literal notranslate"><span class="pre">RequestContext.copy()</span></code></a></li> <li><a class="reference internal" href="#flask.ctx.RequestContext.match_request"><code class="docutils literal notranslate"><span class="pre">RequestContext.match_request()</span></code></a></li> <li><a class="reference internal" href="#flask.ctx.RequestContext.pop"><code class="docutils literal notranslate"><span class="pre">RequestContext.pop()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.flask.globals.request_ctx"><code class="docutils literal notranslate"><span class="pre">flask.globals.request_ctx</span></code></a></li> <li><a class="reference internal" href="#flask.ctx.AppContext"><code class="docutils literal notranslate"><span class="pre">AppContext</span></code></a><ul> <li><a class="reference internal" href="#flask.ctx.AppContext.push"><code class="docutils literal notranslate"><span class="pre">AppContext.push()</span></code></a></li> <li><a class="reference internal" href="#flask.ctx.AppContext.pop"><code class="docutils literal notranslate"><span class="pre">AppContext.pop()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.flask.globals.app_ctx"><code class="docutils literal notranslate"><span class="pre">flask.globals.app_ctx</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState</span></code></a><ul> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.app"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.app</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.blueprint"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.blueprint</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.options"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.options</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.first_registration"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.first_registration</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.subdomain"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.subdomain</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.url_prefix"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.url_prefix</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.url_defaults"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.url_defaults</span></code></a></li> <li><a class="reference internal" href="#flask.blueprints.BlueprintSetupState.add_url_rule"><code class="docutils literal notranslate"><span class="pre">BlueprintSetupState.add_url_rule()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#signals">Signals</a><ul> <li><a class="reference internal" href="#flask.template_rendered"><code class="docutils literal notranslate"><span class="pre">template_rendered</span></code></a></li> <li><a class="reference internal" href="#flask.request_started"><code class="docutils literal notranslate"><span class="pre">request_started</span></code></a></li> <li><a class="reference internal" href="#flask.request_finished"><code class="docutils literal notranslate"><span class="pre">request_finished</span></code></a></li> <li><a class="reference internal" href="#flask.got_request_exception"><code class="docutils literal notranslate"><span class="pre">got_request_exception</span></code></a></li> <li><a class="reference internal" href="#flask.request_tearing_down"><code class="docutils literal notranslate"><span class="pre">request_tearing_down</span></code></a></li> <li><a class="reference internal" href="#flask.appcontext_tearing_down"><code class="docutils literal notranslate"><span class="pre">appcontext_tearing_down</span></code></a></li> <li><a class="reference internal" href="#flask.appcontext_pushed"><code class="docutils literal notranslate"><span class="pre">appcontext_pushed</span></code></a></li> <li><a class="reference internal" href="#flask.appcontext_popped"><code class="docutils literal notranslate"><span class="pre">appcontext_popped</span></code></a></li> <li><a class="reference internal" href="#flask.message_flashed"><code class="docutils literal notranslate"><span class="pre">message_flashed</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#class-based-views">Class-Based Views</a><ul> <li><a class="reference internal" href="#flask.views.View"><code class="docutils literal notranslate"><span class="pre">View</span></code></a><ul> <li><a class="reference internal" href="#flask.views.View.methods"><code class="docutils literal notranslate"><span class="pre">View.methods</span></code></a></li> <li><a class="reference internal" href="#flask.views.View.provide_automatic_options"><code class="docutils literal notranslate"><span class="pre">View.provide_automatic_options</span></code></a></li> <li><a class="reference internal" href="#flask.views.View.decorators"><code class="docutils literal notranslate"><span class="pre">View.decorators</span></code></a></li> <li><a class="reference internal" href="#flask.views.View.init_every_request"><code class="docutils literal notranslate"><span class="pre">View.init_every_request</span></code></a></li> <li><a class="reference internal" href="#flask.views.View.dispatch_request"><code class="docutils literal notranslate"><span class="pre">View.dispatch_request()</span></code></a></li> <li><a class="reference internal" href="#flask.views.View.as_view"><code class="docutils literal notranslate"><span class="pre">View.as_view()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.views.MethodView"><code class="docutils literal notranslate"><span class="pre">MethodView</span></code></a><ul> <li><a class="reference internal" href="#flask.views.MethodView.dispatch_request"><code class="docutils literal notranslate"><span class="pre">MethodView.dispatch_request()</span></code></a></li> </ul> </li> </ul> </li> <li><a class="reference internal" href="#url-route-registrations">URL Route Registrations</a></li> <li><a class="reference internal" href="#view-function-options">View Function Options</a></li> <li><a class="reference internal" href="#command-line-interface">Command Line Interface</a><ul> <li><a class="reference internal" href="#flask.cli.FlaskGroup"><code class="docutils literal notranslate"><span class="pre">FlaskGroup</span></code></a><ul> <li><a class="reference internal" href="#flask.cli.FlaskGroup.get_command"><code class="docutils literal notranslate"><span class="pre">FlaskGroup.get_command()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.FlaskGroup.list_commands"><code class="docutils literal notranslate"><span class="pre">FlaskGroup.list_commands()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.FlaskGroup.make_context"><code class="docutils literal notranslate"><span class="pre">FlaskGroup.make_context()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.FlaskGroup.parse_args"><code class="docutils literal notranslate"><span class="pre">FlaskGroup.parse_args()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.cli.AppGroup"><code class="docutils literal notranslate"><span class="pre">AppGroup</span></code></a><ul> <li><a class="reference internal" href="#flask.cli.AppGroup.command"><code class="docutils literal notranslate"><span class="pre">AppGroup.command()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.AppGroup.group"><code class="docutils literal notranslate"><span class="pre">AppGroup.group()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.cli.ScriptInfo"><code class="docutils literal notranslate"><span class="pre">ScriptInfo</span></code></a><ul> <li><a class="reference internal" href="#flask.cli.ScriptInfo.app_import_path"><code class="docutils literal notranslate"><span class="pre">ScriptInfo.app_import_path</span></code></a></li> <li><a class="reference internal" href="#flask.cli.ScriptInfo.create_app"><code class="docutils literal notranslate"><span class="pre">ScriptInfo.create_app</span></code></a></li> <li><a class="reference internal" href="#flask.cli.ScriptInfo.data"><code class="docutils literal notranslate"><span class="pre">ScriptInfo.data</span></code></a></li> <li><a class="reference internal" href="#flask.cli.ScriptInfo.load_dotenv_defaults"><code class="docutils literal notranslate"><span class="pre">ScriptInfo.load_dotenv_defaults</span></code></a></li> <li><a class="reference internal" href="#flask.cli.ScriptInfo.load_app"><code class="docutils literal notranslate"><span class="pre">ScriptInfo.load_app()</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#flask.cli.load_dotenv"><code class="docutils literal notranslate"><span class="pre">load_dotenv()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.with_appcontext"><code class="docutils literal notranslate"><span class="pre">with_appcontext()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.pass_script_info"><code class="docutils literal notranslate"><span class="pre">pass_script_info()</span></code></a></li> <li><a class="reference internal" href="#flask.cli.run_command"><code class="docutils literal notranslate"><span class="pre">run_command</span></code></a></li> <li><a class="reference internal" href="#flask.cli.shell_command"><code class="docutils literal notranslate"><span class="pre">shell_command</span></code></a></li> </ul> </li> </ul> </li> </ul> <h3>Navigation</h3> <ul> <li><a href="../">Overview</a> <ul> <li>Previous: <a href="../async-await/" title="previous chapter">Using <code class="docutils literal notranslate"><span class="pre">async</span></code> and <code class="docutils literal notranslate"><span class="pre">await</span></code></a> <li>Next: <a href="../design/" title="next chapter">Design Decisions in Flask</a> </ul> </li> </ul> <search id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search/" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </search> <script>document.getElementById('searchbox').style.display = "block"</script><div id="ethical-ad-placement"></div> </div> </div> <div class="clearer"></div> </div> <div class="footer" role="contentinfo"> &#169; Copyright 2010 Pallets. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3. </div> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10