Skip to content
Myr

Rewrite deployment docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 0a7cc2b · Browse files · 2 files+50 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+50 added−50 removed

  • other:+50 added−50 removed

2 files+50 added−50 removed

modified:docs/deploying/index.rst+25 added-10 removed
1 unmodified line
23Deployment Options4==================56Depending on what you have available there are multiple ways to run7Flask applications. You can use the builtin server during development,8but you should use a full deployment option for production applications.9(Do not use the builtin development server in production.) Several10options are available and documented here.6Flask's builtin server is lightweight and easy to use, but it has multiple7problems which you don't want to face in production. With default settings, it8can handle only one request at a time, and even if you manage to circumvent9this problem, it has too many scaling problems that would make it unsuitable10for production. **Do not use the builtin development server in production**.11Some of the options available for properly running Flask in production are12documented here.1312If you have a different WSGI server look up the server documentation13about how to use a WSGI app with it. Just remember that your14:class:`Flask` application object is the actual WSGI application.14If you want to deploy your Flask application to a WSGI server not listed here,15look up the server documentation about how to use a WSGI app with it. Just16remember that your :class:`Flask` application object is the actual WSGI17application.1816For hosted options to get up and running quickly, see17:ref:`quickstart_deployment` in the Quickstart.1920Hosted options21--------------2223- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_24- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_25 with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_26- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_27- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_28- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_293031Self-hosted options32-------------------3334.. toctree::35 :maxdepth: 23637 mod_wsgi
4 unmodified lines
modified:docs/quickstart.rst+25 added-40 removed
18 unmodified lines
19 @app.route('/')20 def hello_world():21 return 'Hello World!'2223Just save it as `hello.py` (or something similar) and run it with your Python24interpreter. Make sure to not call your application `flask.py` because this25would conflict with Flask itself.23So what does that code do?2427To run the application you can either use the ``flask`` command or28python's ``-m`` switch with Flask::2930 $ flask -a hello run31 * Running on http://127.0.0.1:5000/3233or alternatively::3435 $ python -m flask -a hello run36 * Running on http://127.0.0.1:5000/3738Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you39should see your hello world greeting.4041So what did that code do?42251. First we imported the :class:`~flask.Flask` class. An instance of this26 class will be our WSGI application.272. Next we create an instance of this class. The first argument is the name of28 the application's module or package. If you are using a single module (as
6 unmodified lines
35 should trigger our function.364. The function is given a name which is also used to generate URLs for that37 particular function, and returns the message we want to display in the38 user's browser.575. Finally we use the Flask development server to run the local server58 with our application.3960To stop the server, hit control-C.40Just save it as `hello.py` (or something similar). Make sure to not call your41application `flask.py` because this would conflict with Flask itself.4243To run the application you can either use the ``flask`` command or44python's ``-m`` switch with Flask::4546 $ flask -a hello run47 * Running on http://127.0.0.1:5000/4849or alternatively::5051 $ python -m flask -a hello run52 * Running on http://127.0.0.1:5000/5354This launches a very simple builtin server, which is good enough for testing55but probably not what you want to use in production. For deployment options see56:ref:`deployment`.5758Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you59should see your hello world greeting. To stop the server, hit control-C.6061.. _public-server:6263.. admonition:: Externally Visible Server64
9 unmodified lines
74 flask -a hello run --host=0.0.0.07576 This tells your operating system to listen on all public IPs.777879What to do if the Server does not Start80---------------------------------------8182In case the ``python -m flask`` fails or ``flask`` does not exist,
774 unmodified lines
857:class:`~logging.Logger`, so head over to the official `logging858documentation <https://docs.python.org/library/logging.html>`_ for more859information.860861Read more on :ref:`errorhandling`.862863Hooking in WSGI Middlewares864---------------------------865866If you want to add a WSGI middleware to your application you can wrap the
3 unmodified lines
870871 from werkzeug.contrib.fixers import LighttpdCGIRootFix872 app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)873872.. _quickstart_deployment:873874Deploying to a Web Server875-------------------------876877Ready to deploy your new Flask app? To wrap up the quickstart, you can878immediately deploy to a hosted platform, all of which offer a free plan for879small projects:880881- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_882- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_883 with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_884885Other places where you can host your Flask app:886887- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_888- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_889- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_890891If you manage your own hosts and would like to host yourself, see the chapter892on :ref:`deployment`.877Ready to deploy your new Flask app? Go to :ref:`deployment`.