Skip to content
Myr

deploy.rst

This file

Path

docs/tutorial/deploy.rst

111 lines · 3.6 KiB

Last changed by

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

History of this file

Take it

The walk stopped after 200 commits: lines older than 8bfce88 point at it.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 1–16why, one step back
1Deploy to Production
2====================34This part of the tutorial assumes you have a server that you want to5deploy your application to. It gives an overview of how to create the6distribution file and install it, but won't go into specifics about7what server or software to use. You can set up a new environment on your8development computer to try out the instructions below, but probably9shouldn't use it for hosting a real public application. See10:doc:`/deploying/index` for a list of many different ways to host your11application.121314Build and Install15-----------------16

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 17–18why, one step back
17When you want to deploy your application elsewhere, you build a *wheel*
18(``.whl``) file. Install and use the ``build`` tool to do this.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 19–21why, one step back
19
20.. code-block:: none21

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 22–23why, one step back
22 $ pip install build
23 $ python -m build --wheel

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 24–41why, one step back
24
25You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. The26file name is in the format of {project name}-{version}-{python tag}27-{abi tag}-{platform tag}.2829Copy this file to another machine,30:ref:`set up a new virtualenv <install-create-env>`, then install the31file with ``pip``.3233.. code-block:: none3435 $ pip install flaskr-1.0.0-py3-none-any.whl3637Pip will install your project along with its dependencies.3839Since this is a different machine, you need to run ``init-db`` again to40create the database in the instance folder.41

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 42why, one step back
42 .. code-block:: text

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 43why, one step back
43

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 44why, one step back
44 $ flask --app flaskr init-db

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 45–47why, one step back
45
46When Flask detects that it's installed (not in editable mode), it uses47a different directory for the instance folder. You can find it at

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

line 48why, one step back
48``.venv/var/flaskr-instance`` instead.

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 49–62why, one step back
49
5051Configure the Secret Key52------------------------5354In the beginning of the tutorial that you gave a default value for55:data:`SECRET_KEY`. This should be changed to some random bytes in56production. Otherwise, attackers could use the public ``'dev'`` key to57modify the session cookie, or anything else that uses the secret key.5859You can use the following command to output a random secret key:6061.. code-block:: none62

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 63why, one step back
63 $ python -c 'import secrets; print(secrets.token_hex())'

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 64why, one step back
64

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 65why, one step back
65 '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 66–70why, one step back
66
67Create the ``config.py`` file in the instance folder, which the factory68will read from if it exists. Copy the generated value into it.6970.. code-block:: python

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

line 71why, one step back
71 :caption: ``.venv/var/flaskr-instance/config.py``

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

line 72why, one step back
72

Merge branch '2.0.x'David Lordbefore adoption0ae0f59

line 73why, one step back
73 SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf'

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 74–94why, one step back
74
75You can also set any other necessary configuration here, although76``SECRET_KEY`` is the only one needed for Flaskr.777879Run with a Production Server80----------------------------8182When running publicly rather than in development, you should not use the83built-in development server (``flask run``). The development server is84provided by Werkzeug for convenience, but is not designed to be85particularly efficient, stable, or secure.8687Instead, use a production WSGI server. For example, to use `Waitress`_,88first install it in the virtual environment:8990.. code-block:: none9192 $ pip install waitress9394You need to tell Waitress about your application, but it doesn't use

Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727

line 95why, one step back
95``--app`` like ``flask run`` does. You need to tell it to import and

Minor docs fixes. (#3988)Joshua Bronsonbefore adoption8bfce88

lines 96–111why, one step back
96call the application factory to get an application object.
9798.. code-block:: none99100 $ waitress-serve --call 'flaskr:create_app'101102 Serving on http://0.0.0.0:8080103104See :doc:`/deploying/index` for a list of many different ways to host105your application. Waitress is just an example, chosen for the tutorial106because it supports both Windows and Linux. There are many more WSGI107servers and deployment options that you may choose for your project.108109.. _Waitress: https://docs.pylonsproject.org/projects/waitress/en/stable/110111Continue to :doc:`next`.