Server - Contents

Flask

revised: 26-Apr-2022

A 3-page site example

Prerequisites: Basic Server (Debian 10.3 64bit) with Webmin, FTP, Firewall and Fail2Ban: a server linked with a domain name (eg. example.com)

For a National Office or a Local Assembly seeking a more complex, adaptable website with the option to have a mail-form within and possibly including a Google map link, then Flask (a python-based environment) offers significant potential and ease.

As with the BasicSite, the setup proposed here is to have the Flask website up and running first on the PC then to have the same site established on the server (running iRedmail/Nginx) with the two sites synchronized via FTP (eg. FileZilla)

Part A: Creating the Python/Flask Environment on the PC

Step01: Install Python on a PC (Windows)

As Python 2 has become outdated, it is recommended to install the version 3 of Python (currently at version 3.10) by following this link: how-to-install-python-on-windows

Step02 Install Flask

Check to update pip and install Flask and ipython, using these commands via 'PowerShell'[Win10] or in Win 7+, typing in 'cmd' after opening the Windows Start button. Note: Ipython provides more information than python alone.
pip install Flask ipython

Step03 Create a 'Scripts' folder as a sub-directory of 'Documents' and add there a folder called 'myapp'. Open a new file in a text editor (eg. Notepad++), copy & paste this text ( myproject.py) within and save it in the 'myapp' folder as 'project.py'

Open the console (via 'PowerShell'[Win10] or in Win 7+, typing in 'cmd')and enter these commands:

cd Documents\Scripts\myapp
ipython myproject.py

Enter in the browser, type in this url: localhost:5000 (eg. http://localhost:5000), the result should 'Hello there!' in red letters. Type in the console: 'ctl'+c to exit.

Download the 3-page Flask Website and unzip in the 'Scripts' folder and do the following:

cd Documents\Scripts\myapp
ipython myproject.py // This Flask website should appear.

Step04(Optional) Site with Email Contact Form

Where the website associated with a mailserver (eg. using iRedmail), then there is the option to add the following extensions:

python -m pip install flask-wtf flask-mail email_validator

Download the enhanced 3-page Flask Website and unzip in the 'Scripts' folder and redo the above

Flask Flask-PartB
Flask-PartC Flask-PartD