<h1>Development Server<aclass="headerlink"href="#development-server"title="Link to this heading">¶</a></h1>
<p>Flask provides a <codeclass="docutils literal notranslate"><spanclass="pre">run</span></code> command to run the application with a development server. In
debug mode, this server provides an interactive debugger and will reload when code is
changed.</p>
<divclass="admonition warning">
<pclass="admonition-title">Warning</p>
<p>Do not use the development server when deploying to production. It
is intended for use only during local development. It is not
designed to be particularly efficient, stable, or secure.</p>
<p>See <aclass="reference internal"href="deploying/index.html"><spanclass="doc">Deploying to Production</span></a> for deployment options.</p>
</div>
<sectionid="command-line">
<h2>Command Line<aclass="headerlink"href="#command-line"title="Link to this heading">¶</a></h2>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span></code> CLI command is the recommended way to run the development server. Use
the <codeclass="docutils literal notranslate"><spanclass="pre">--app</span></code> option to point to your application, and the <codeclass="docutils literal notranslate"><spanclass="pre">--debug</span></code> option to enable
debug mode.</p>
<divclass="highlight-text notranslate"><divclass="highlight"><pre><span></span>$ flask --app hello run --debug
<p>This enables debug mode, including the interactive debugger and reloader, and then
starts the server on <aclass="reference external"href="http://localhost:5000/">http://localhost:5000/</a>. Use <codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span><spanclass="pre">--help</span></code> to see the
available options, and <aclass="reference internal"href="cli.html"><spanclass="doc">Command Line Interface</span></a> for detailed instructions about configuring and using
the CLI.</p>
<sectionid="address-already-in-use">
<spanid="id1"></span><h3>Address already in use<aclass="headerlink"href="#address-already-in-use"title="Link to this heading">¶</a></h3>
<p>If another program is already using port 5000, you’ll see an <codeclass="docutils literal notranslate"><spanclass="pre">OSError</span></code>
when the server tries to start. It may have one of the following
<p>Either identify and stop the other program, or use
<codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span><spanclass="pre">--port</span><spanclass="pre">5001</span></code> to pick a different port.</p>
<p>You can use <codeclass="docutils literal notranslate"><spanclass="pre">netstat</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">lsof</span></code> to identify what process id is using
a port, then use other operating system tools stop that process. The
following example shows that process id 6847 is using port 5000.</p>
<h3>Deferred Errors on Reload<aclass="headerlink"href="#deferred-errors-on-reload"title="Link to this heading">¶</a></h3>
<p>When using the <codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span></code> command with the reloader, the server will
continue to run even if you introduce syntax errors or other
initialization errors into the code. Accessing the site will show the
interactive debugger for the error, rather than crashing the server.</p>
<p>If a syntax error is already present when calling <codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span></code>, it will
fail immediately and show the traceback rather than waiting until the
site is accessed. This is intended to make errors more visible initially
while still allowing the server to handle errors on reload.</p>
<h2>In Code<aclass="headerlink"href="#in-code"title="Link to this heading">¶</a></h2>
<p>The development server can also be started from Python with the <aclass="reference internal"href="api.html#flask.Flask.run"title="flask.Flask.run"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">Flask.run()</span></code></a>
method. This method takes arguments similar to the CLI options to control the server.
The main difference from the CLI command is that the server will crash if there are
errors when reloading. <codeclass="docutils literal notranslate"><spanclass="pre">debug=True</span></code> can be passed to enable debug mode.</p>
<p>Place the call in a main block, otherwise it will interfere when trying to import and
run the application with a production server later.</p>