<h1>Deploy to Production<aclass="headerlink"href="#deploy-to-production"title="Link to this heading">¶</a></h1>
<p>This part of the tutorial assumes you have a server that you want to
deploy your application to. It gives an overview of how to create the
distribution file and install it, but won’t go into specifics about
what server or software to use. You can set up a new environment on your
development computer to try out the instructions below, but probably
shouldn’t use it for hosting a real public application. See
<aclass="reference internal"href="../deploying/index.html"><spanclass="doc">Deploying to Production</span></a> for a list of many different ways to host your
application.</p>
<sectionid="build-and-install">
<h2>Build and Install<aclass="headerlink"href="#build-and-install"title="Link to this heading">¶</a></h2>
<p>When you want to deploy your application elsewhere, you build a <em>wheel</em>
(<codeclass="docutils literal notranslate"><spanclass="pre">.whl</span></code>) file. Install and use the <codeclass="docutils literal notranslate"><spanclass="pre">build</span></code> tool to do this.</p>
<p>You can find the file in <codeclass="docutils literal notranslate"><spanclass="pre">dist/flaskr-1.0.0-py3-none-any.whl</span></code>. The
file name is in the format of {project name}-{version}-{python tag}
-{abi tag}-{platform tag}.</p>
<p>Copy this file to another machine,
<aclass="reference internal"href="../installation.html#install-create-env"><spanclass="std std-ref">set up a new virtualenv</span></a>, then install the
file with <codeclass="docutils literal notranslate"><spanclass="pre">pip</span></code>.</p>
<h2>Configure the Secret Key<aclass="headerlink"href="#configure-the-secret-key"title="Link to this heading">¶</a></h2>
<p>In the beginning of the tutorial that you gave a default value for
<aclass="reference internal"href="../config.html#SECRET_KEY"title="SECRET_KEY"><codeclass="xref py py-data docutils literal notranslate"><spanclass="pre">SECRET_KEY</span></code></a>. This should be changed to some random bytes in
production. Otherwise, attackers could use the public <codeclass="docutils literal notranslate"><spanclass="pre">'dev'</span></code> key to
modify the session cookie, or anything else that uses the secret key.</p>
<p>You can use the following command to output a random secret key:</p>
<divclass="code-block-caption"><spanclass="caption-text"><codeclass="docutils literal notranslate"><spanclass="pre">.venv/var/flaskr-instance/config.py</span></code></span><aclass="headerlink"href="#id1"title="Link to this code">¶</a></div>
<p>You can also set any other necessary configuration here, although
<codeclass="docutils literal notranslate"><spanclass="pre">SECRET_KEY</span></code> is the only one needed for Flaskr.</p>
</section>
<sectionid="run-with-a-production-server">
<h2>Run with a Production Server<aclass="headerlink"href="#run-with-a-production-server"title="Link to this heading">¶</a></h2>
<p>When running publicly rather than in development, you should not use the
built-in development server (<codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span></code>). The development server is
provided by Werkzeug for convenience, but is not designed to be
particularly efficient, stable, or secure.</p>
<p>Instead, use a production WSGI server. For example, to use <aclass="reference external"href="https://docs.pylonsproject.org/projects/waitress/en/stable/">Waitress</a>,
<p>You need to tell Waitress about your application, but it doesn’t use
<codeclass="docutils literal notranslate"><spanclass="pre">--app</span></code> like <codeclass="docutils literal notranslate"><spanclass="pre">flask</span><spanclass="pre">run</span></code> does. You need to tell it to import and
call the application factory to get an application object.</p>
<p>See <aclass="reference internal"href="../deploying/index.html"><spanclass="doc">Deploying to Production</span></a> for a list of many different ways to host
your application. Waitress is just an example, chosen for the tutorial
because it supports both Windows and Linux. There are many more WSGI
servers and deployment options that you may choose for your project.</p>
<p>Continue to <aclass="reference internal"href="next.html"><spanclass="doc">Keep Developing!</span></a>.</p>