forked from orbit-oss/flask
Rewrite deployment docs
This commit is contained in:
parent
0a7cc2b113
commit
3d3b809347
2 changed files with 50 additions and 50 deletions
|
|
@ -3,18 +3,33 @@
|
||||||
Deployment Options
|
Deployment Options
|
||||||
==================
|
==================
|
||||||
|
|
||||||
Depending on what you have available there are multiple ways to run
|
Flask's builtin server is lightweight and easy to use, but it has multiple
|
||||||
Flask applications. You can use the builtin server during development,
|
problems which you don't want to face in production. With default settings, it
|
||||||
but you should use a full deployment option for production applications.
|
can handle only one request at a time, and even if you manage to circumvent
|
||||||
(Do not use the builtin development server in production.) Several
|
this problem, it has too many scaling problems that would make it unsuitable
|
||||||
options are available and documented here.
|
for production. **Do not use the builtin development server in production**.
|
||||||
|
Some of the options available for properly running Flask in production are
|
||||||
|
documented here.
|
||||||
|
|
||||||
If you have a different WSGI server look up the server documentation
|
If you want to deploy your Flask application to a WSGI server not listed here,
|
||||||
about how to use a WSGI app with it. Just remember that your
|
look up the server documentation about how to use a WSGI app with it. Just
|
||||||
:class:`Flask` application object is the actual WSGI application.
|
remember that your :class:`Flask` application object is the actual WSGI
|
||||||
|
application.
|
||||||
|
|
||||||
For hosted options to get up and running quickly, see
|
|
||||||
:ref:`quickstart_deployment` in the Quickstart.
|
Hosted options
|
||||||
|
--------------
|
||||||
|
|
||||||
|
- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_
|
||||||
|
- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_
|
||||||
|
with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_
|
||||||
|
- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_
|
||||||
|
- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_
|
||||||
|
- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_
|
||||||
|
|
||||||
|
|
||||||
|
Self-hosted options
|
||||||
|
-------------------
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
|
||||||
|
|
@ -20,25 +20,7 @@ A minimal Flask application looks something like this::
|
||||||
def hello_world():
|
def hello_world():
|
||||||
return 'Hello World!'
|
return 'Hello World!'
|
||||||
|
|
||||||
Just save it as `hello.py` (or something similar) and run it with your Python
|
So what does that code do?
|
||||||
interpreter. Make sure to not call your application `flask.py` because this
|
|
||||||
would conflict with Flask itself.
|
|
||||||
|
|
||||||
To run the application you can either use the ``flask`` command or
|
|
||||||
python's ``-m`` switch with Flask::
|
|
||||||
|
|
||||||
$ flask -a hello run
|
|
||||||
* Running on http://127.0.0.1:5000/
|
|
||||||
|
|
||||||
or alternatively::
|
|
||||||
|
|
||||||
$ python -m flask -a hello run
|
|
||||||
* Running on http://127.0.0.1:5000/
|
|
||||||
|
|
||||||
Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you
|
|
||||||
should see your hello world greeting.
|
|
||||||
|
|
||||||
So what did that code do?
|
|
||||||
|
|
||||||
1. First we imported the :class:`~flask.Flask` class. An instance of this
|
1. First we imported the :class:`~flask.Flask` class. An instance of this
|
||||||
class will be our WSGI application.
|
class will be our WSGI application.
|
||||||
|
|
@ -54,10 +36,27 @@ So what did that code do?
|
||||||
4. The function is given a name which is also used to generate URLs for that
|
4. The function is given a name which is also used to generate URLs for that
|
||||||
particular function, and returns the message we want to display in the
|
particular function, and returns the message we want to display in the
|
||||||
user's browser.
|
user's browser.
|
||||||
5. Finally we use the Flask development server to run the local server
|
|
||||||
with our application.
|
|
||||||
|
|
||||||
To stop the server, hit control-C.
|
Just save it as `hello.py` (or something similar). Make sure to not call your
|
||||||
|
application `flask.py` because this would conflict with Flask itself.
|
||||||
|
|
||||||
|
To run the application you can either use the ``flask`` command or
|
||||||
|
python's ``-m`` switch with Flask::
|
||||||
|
|
||||||
|
$ flask -a hello run
|
||||||
|
* Running on http://127.0.0.1:5000/
|
||||||
|
|
||||||
|
or alternatively::
|
||||||
|
|
||||||
|
$ python -m flask -a hello run
|
||||||
|
* Running on http://127.0.0.1:5000/
|
||||||
|
|
||||||
|
This launches a very simple builtin server, which is good enough for testing
|
||||||
|
but probably not what you want to use in production. For deployment options see
|
||||||
|
:ref:`deployment`.
|
||||||
|
|
||||||
|
Now head over to `http://127.0.0.1:5000/ <http://127.0.0.1:5000/>`_, and you
|
||||||
|
should see your hello world greeting. To stop the server, hit control-C.
|
||||||
|
|
||||||
.. _public-server:
|
.. _public-server:
|
||||||
|
|
||||||
|
|
@ -76,6 +75,7 @@ To stop the server, hit control-C.
|
||||||
|
|
||||||
This tells your operating system to listen on all public IPs.
|
This tells your operating system to listen on all public IPs.
|
||||||
|
|
||||||
|
|
||||||
What to do if the Server does not Start
|
What to do if the Server does not Start
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
|
@ -858,6 +858,8 @@ The attached :attr:`~flask.Flask.logger` is a standard logging
|
||||||
documentation <https://docs.python.org/library/logging.html>`_ for more
|
documentation <https://docs.python.org/library/logging.html>`_ for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
|
Read more on :ref:`errorhandling`.
|
||||||
|
|
||||||
Hooking in WSGI Middlewares
|
Hooking in WSGI Middlewares
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|
@ -869,24 +871,7 @@ can do it like this::
|
||||||
from werkzeug.contrib.fixers import LighttpdCGIRootFix
|
from werkzeug.contrib.fixers import LighttpdCGIRootFix
|
||||||
app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)
|
app.wsgi_app = LighttpdCGIRootFix(app.wsgi_app)
|
||||||
|
|
||||||
.. _quickstart_deployment:
|
|
||||||
|
|
||||||
Deploying to a Web Server
|
Deploying to a Web Server
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
Ready to deploy your new Flask app? To wrap up the quickstart, you can
|
Ready to deploy your new Flask app? Go to :ref:`deployment`.
|
||||||
immediately deploy to a hosted platform, all of which offer a free plan for
|
|
||||||
small projects:
|
|
||||||
|
|
||||||
- `Deploying Flask on Heroku <https://devcenter.heroku.com/articles/getting-started-with-python>`_
|
|
||||||
- `Deploying WSGI on dotCloud <http://docs.dotcloud.com/services/python/>`_
|
|
||||||
with `Flask-specific notes <http://flask.pocoo.org/snippets/48/>`_
|
|
||||||
|
|
||||||
Other places where you can host your Flask app:
|
|
||||||
|
|
||||||
- `Deploying Flask on Webfaction <http://flask.pocoo.org/snippets/65/>`_
|
|
||||||
- `Deploying Flask on Google App Engine <https://github.com/kamalgill/flask-appengine-template>`_
|
|
||||||
- `Sharing your Localhost Server with Localtunnel <http://flask.pocoo.org/snippets/89/>`_
|
|
||||||
|
|
||||||
If you manage your own hosts and would like to host yourself, see the chapter
|
|
||||||
on :ref:`deployment`.
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue