Server - Contents

Flask Roles Demo

revised 05-Sep-2023

For an institutional website, the need to have specific pages or areas designated as private and accessible only to authorized person is often felt. The demo here provides a learning environment but also a beginning of such an equipped website.

Found on an intergration of Flask-Login, the example below relies heavily on the example with its code base here.It is expanded to fit within a three page website with a contact page to show its abilities. As always, glance throught the README file and the __init__.py files for a better understanding of the app.

The Setup

Download this compressed folder: flklogin.tar.gz (19Kb) and upload it (eg. via Filezilla - FTP client) to a home directory (eg. /home/sammy).

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

sammy@imega:$ tar -xvf flklogin230907.tar.gz
sammy@imega:$ cd flklogin
sammy@imega:~/flklogin $ python3 -m venv venv
sammy@imega:~/flklogin $ . venv/bin/activate  Note: the "."
(venv)sammy@imega:$ pip install -r requirements
(venv)sammy@imega:$ export FLASK_APP=src
(venv)sammy@imega:$ python3 manage.py create_admin Create an Admin [see README for an existing admin & password
(venv)sammy@imega:$ python3 run.py

The app will now be served on http://0.0.0.0:5000 and one can see the app via the browser at http://(MyIP or MyDomain):5000 and logon with your Admin details

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/flklogin the file: wsgi.py:

Enter the following commands:

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

Note:
1. 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. 2. Set the 'debug' to False in the __init__.py file

Flask Blog Demo Advance Flask
Flask Security-Roles Demo