Python Flask Web Server

Posted on

To start install MariaDB package for development

sudo apt-get install libmariadbclient-dev

Create Directory for site and templates directory

mkdir net
cd net
mkdir templates

Create a virtual environment called myenv

python3 -m venv myenv

Activate the myenv python environment

source myenv/bin/activate

Check version of Python for virtual environment

sudo nano ~/.profile

At the bottom of the file, type in the following line:


Exit the virtual environment

source ~/.profile

Install Flask in the virtual environment

pip3 install flask

Install the SQL python packages:

pip3 install mysql
pip3 install mysql-connector  

Create Database Schema

login to MariaDB as root and create database and tables

mariadb -u root -p
USE mydb;
CREATE TABLE posts ( id INTEGER PRIMARY KEY AUTO_INCREMENT, username CHAR(25), content CHAR(150));
INSERT INTO posts ( username, content) VALUES( ‘gilmedel’, ‘First Post’);

Create Server application

Start by creating file
Then create file
python code:

Create index.html in the template directory for Flask

Save all files then run to start the Python3, Flask, MariaDB server


Navigate to the webpage http://localhost:5000