Flask is a
web microframework for Python under the BSD license. On Serv00.com servers it is possible to run websites based on this framework thanks to the Phusion Passenger technology.
To run a website written in Flask you must first ensure the correct configuration of the environment and domain. Before proceeding with the next steps, make sure that:
- Added virtualenv for Python environment and installed Flask with:
pip install flask
- The domain is properly added and configured in our DNS.
- Added Python website and the path to the
pythonbinary inside the previously configured environment.
The root directory of the Flask project must be
/usr/home/LOGIN/domains/DOMAIN/public_python. You should also delete the
index.html file with the command:
Configuration of Phusion Passenger
The last step is to create a configuration for the Phusion Passenger server, which is responsible for running the Flask application. In the Flask project directory (
/usr/home/LOGIN/domains/DOMAIN/public_python) create a file
passenger_wsgi.py and place the following content in it, modifying the import line:
import sys, os sys.path.append(os.getcwd()) from application import app as application
application.py file (to be placed in the website directory to test Flask):
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run()
To disable buffering, send the
X-Accel-Buffering: no header in the response header - for example, using
resp = Response(stream_with_context(PARAMETERS)) resp.headers['X-Accel-Buffering'] = 'no'