deploy.rst
This file
Path
docs/tutorial/deploy.rst
121 lines · 3.8 KiB
Last changed by
fix explanation of wheel name (#3848)jordivandoorenbefore adoption7d3ae48
History of this fileTake it
The walk stopped after 200 commits: lines older than 0cbe698 point at it.
Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 1–23why, one step back1Deploy to Production2====================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-----------------1617When you want to deploy your application elsewhere, you build a18distribution file. The current standard for Python distribution is the19*wheel* format, with the ``.whl`` extension. Make sure the wheel library20is installed first:2122.. code-block:: none23Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 24why, one step back24 $ pip install wheelMerge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 25–31why, one step back2526Running ``setup.py`` with Python gives you a command line tool to issue27build-related commands. The ``bdist_wheel`` command will build a wheel28distribution file.2930.. code-block:: none31Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 32why, one step back32 $ python setup.py bdist_wheelMerge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 33–34why, one step back3334You can find the file in ``dist/flaskr-1.0.0-py3-none-any.whl``. Thefix explanation of wheel name (#3848)jordivandoorenbefore adoption7d3ae48
lines 35–36why, one step back35file name is in the format of {project name}-{version}-{python tag}36-{abi tag}-{platform tag}.Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 37–43why, one step back3738Copy this file to another machine,39:ref:`set up a new virtualenv <install-create-env>`, then install the40file with ``pip``.4142.. code-block:: none43Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 44why, one step back44 $ pip install flaskr-1.0.0-py3-none-any.whlMerge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 45–52why, one step back4546Pip will install your project along with its dependencies.4748Since this is a different machine, you need to run ``init-db`` again to49create the database in the instance folder.5051.. code-block:: none52Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
lines 53–54why, one step back53 $ export FLASK_APP=flaskr54 $ flask init-dbMerge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 55–72why, one step back5556When Flask detects that it's installed (not in editable mode), it uses57a different directory for the instance folder. You can find it at58``venv/var/flaskr-instance`` instead.596061Configure the Secret Key62------------------------6364In the beginning of the tutorial that you gave a default value for65:data:`SECRET_KEY`. This should be changed to some random bytes in66production. Otherwise, attackers could use the public ``'dev'`` key to67modify the session cookie, or anything else that uses the secret key.6869You can use the following command to output a random secret key:7071.. code-block:: none72Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 73why, one step back73 $ python -c 'import os; print(os.urandom(16))'Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 74–101why, one step back7475 b'_5#y2L"F4Q8z\n\xec]/'7677Create the ``config.py`` file in the instance folder, which the factory78will read from if it exists. Copy the generated value into it.7980.. code-block:: python81 :caption: ``venv/var/flaskr-instance/config.py``8283 SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'8485You can also set any other necessary configuration here, although86``SECRET_KEY`` is the only one needed for Flaskr.878889Run with a Production Server90----------------------------9192When running publicly rather than in development, you should not use the93built-in development server (``flask run``). The development server is94provided by Werkzeug for convenience, but is not designed to be95particularly efficient, stable, or secure.9697Instead, use a production WSGI server. For example, to use `Waitress`_,98first install it in the virtual environment:99100.. code-block:: none101Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 102why, one step back102 $ pip install waitressMerge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 103–109why, one step back103104You need to tell Waitress about your application, but it doesn't use105``FLASK_APP`` like ``flask run`` does. You need to tell it to import and106call the application factory to get an application object.107108.. code-block:: none109Add prefix for all commands in documentation (#2877)Grey Libefore adoption21b0aa6
line 110why, one step back110 $ waitress-serve --call 'flaskr:create_app'Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 111–118why, one step back111112 Serving on http://0.0.0.0:8080113114See :doc:`/deploying/index` for a list of many different ways to host115your application. Waitress is just an example, chosen for the tutorial116because it supports both Windows and Linux. There are many more WSGI117servers and deployment options that you may choose for your project.118Merge branch '1.0.x'David Lordbefore adoption1351d0a
line 119why, one step back119.. _Waitress: https://docs.pylonsproject.org/projects/waitress/en/stable/Merge pull request #2665 from fprocess/2651-get_json's-silent-option-weird-side-effectDavid Lordbefore adoption0cbe698
lines 120–121why, one step back120121Continue to :doc:`next`.