Skip to content
Myr

Merge branch 'flask_deployment_docs'

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

Conflicts: docs/quickstart.rst

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 86525d9, 5c6d789 · Browse files · 2 files+47 added−49 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+47 added−49 removed

  • other:+47 added−49 removed

2 files+47 added−49 removed

modified:docs/deploying/index.rst+22 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.6While lightweight and easy to use, **Flask's built-in server is not suitable7for production** as it doesn't scale well and by default serves only one8request at a time. Some of the options available for properly running Flask in9production are documented here.1012If 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.11If you want to deploy your Flask application to a WSGI server not listed here,12look up the server documentation about how to use a WSGI app with it. Just13remember that your :class:`Flask` application object is the actual WSGI14application.1516For hosted options to get up and running quickly, see17:ref:`quickstart_deployment` in the Quickstart.1617Hosted options18--------------1920- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_21- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_22 with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_23- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_24- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_25- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_262728Self-hosted options29-------------------3031.. toctree::32 :maxdepth: 23334 mod_wsgi
4 unmodified lines
modified:docs/quickstart.rst+25 added-39 removed
18 unmodified lines
19 @app.route('/')20 def hello_world():21 return 'Hello World!'2223Just save it as :file:`hello.py` (or something similar) and run it with your Python24interpreter. Make sure to not call your application :file:`flask.py` because this25would conflict with Flask itself.2627To run the application you can either use the :command:`flask` command or28python's :option:`-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.4023So what did that code do?24251. First we imported the :class:`~flask.Flask` class. An instance of this26 class will be our WSGI application.
8 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 :file:`hello.py` (or something similar) and run it with your Python41interpreter. Make sure to not call your application :file:`flask.py` because this42would conflict with Flask itself.4344To run the application you can either use the :command:`flask` command or45python's :option:`-m` switch with Flask::4647 $ flask -a hello run48 * Running on http://127.0.0.1:5000/4950or alternatively::5152 $ python -m flask -a hello run53 * Running on http://127.0.0.1:5000/5455This launches a very simple builtin server, which is good enough for testing56but probably not what you want to use in production. For deployment options see57:ref:`deployment`.5859Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you60should see your hello world greeting.6162.. _public-server:6364.. admonition:: Externally Visible Server65
9 unmodified lines
75 flask -a hello run --host=0.0.0.07677 This tells your operating system to listen on all public IPs.787980What to do if the Server does not Start81---------------------------------------8283In case the ``python -m flask`` fails or :command:`flask` does not exist,
775 unmodified lines
859:class:`~logging.Logger`, so head over to the official `logging860documentation <https://docs.python.org/library/logging.html>`_ for more861information.862863Read more on :ref:`application-errors`.864865Hooking in WSGI Middlewares866---------------------------867868If you want to add a WSGI middleware to your application you can wrap the
3 unmodified lines
872873 from werkzeug.contrib.fixers import LighttpdCGIRootFix874 app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)875873.. _quickstart_deployment:874876Deploying to a Web Server877-------------------------878878Ready to deploy your new Flask app? To wrap up the quickstart, you can879immediately deploy to a hosted platform, all of which offer a free plan for880small projects:881882- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_883- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_884 with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_885886Other places where you can host your Flask app:887888- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_889- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_890- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_891892If you manage your own hosts and would like to host yourself, see the chapter893on :ref:`deployment`.879Ready to deploy your new Flask app? Go to :ref:`deployment`.