Server - Contents

Flask Blog Demo

revised: 08-Jan-2022

The setup described below follows, with very few changes, that found at: Pallets Project git depository.

Steps to the Setup

With the initial virtual environment described in the Flask 3pg Site and assuming a Debian 10 environment:

sammy@imega:$ git clone https://github.com/pallets/flask
sammy@imega:$ cd flask/examples/tutorial
sammy@imega:~flask/examples/tutorial $ virtualenv -p python3 venv
sammy@imega:~flask/examples/tutorial $ . venv/bin/activate  Note: the "."
(venv)sammy@imega:$ pip install -e .  Note: again the "."
(venv)sammy@imega:$ export FLASK_APP=flaskr
(venv)sammy@imega:$ export FLASK_ENV=development
(venv)sammy@imega:$ flask init-db
(venv)sammy@imega:$ flask run  Note: to stop the app from running: press Ctl-c

The result will have the application running at: http://127.0.0.1:5000/ which on a remote server is not readily seen. One option to that the app is active is by running this command via Webmin->Tools->Shell Command then enter: curl http://127.0.0.1:5000/

Instead of running the last command in the aim of making it accessible to a remote browser, enter the following commands:

(venv)sammy@imega:$ pip install waitress
(venv)sammy@imega:$ waitress-serve --call 'flaskr:create_app' Note: to stop the app from running: press Ctl-c

The app will now be served on http://0.0.0.0:8080 and one can see the app via the browser at http://(MyIP or MyDomain):8080

Running the App as a Service

In preparing the app to run through at webserver, one could use uwsgi and by doing the following:
a. Create in directory: /home/sammy/flask/examples/tutorial the file: wsgi.py:

Enter the following commands:

(venv)sammy@imega:$ nano wsgi.py ##copy-paste above instructions.
(venv)sammy@imega:$ pip install uwsgi
(venv)sammy@imega:$ uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app

Note: The above confirms if the settings within wsgi.py are correct. The app should be seen via the browser at http://(MyIP or MyDomain):5000

Using a similar setup described in Step#3 (PartB) in Flask 3pg Site, one can establish the service to be render by the webserver.
Advance Flask Flask Roles Demo
Flask Security-Roles Demo