Hosting in practice
So how does this all work in practice? Well as we saw with Flask, many frameworks come with their own built-in development web servers. However, these are not recommended for use in a production environment as they're generally not designed to be used where security and scalability are important.
Currently, probably the quickest way to host a Python web application with a production quality server is with the Gunicorn server. Using our Flask application from earlier, we can get it up and running using just a few steps. First we install Gunicorn:
$ pip install gunicorn
Next we need to slightly modify our Flask app so that it's use of __builtins__
works correctly under Gunicorn. In your tinyflaskapp.py
file, find the line:
objs = __builtins__.__dict__.items()
Change it to:
objs = __builtins__.items()
Now we can run Gunicorn. From within your Flask application project folder, run the following command:
$ gunicorn --bind 0.0.0.0:5000 tinyflaskapp:app
This will launch...