Intro

This tutorial will be based on creating a CRUD Flask Web app and then deploying it on azure. We will use the PostgreSQL database for this web app. The tutorial has three important parts —

  1. Creating the Web App and testing it locally
  2. Testing locally with database on Azure
  3. Deploying Web App with Docker using Azure DB for PostgreSQL.

What is CRUD

Simple definition for CRUD —

C- Create, R- Read, U- Update, D- Delete

These are the four functionalities that every single web application has. You will see a lot of tutorials for creating a CRUD web app(well, this is also one of that :P). Because generally, this is the next step when you are learning some kind of MVC (Model-View-Controller) framework or programming language.

How to create App

Let’s start, by creating a very simple web app for this. You can clone my Github repo (This repo has the source code to test the webapp locally) and start creating the web app.

Requirements for the Web App:-

Python, Flask, Github, PostgreSQL, Docker

Test locally

After cloning the GitHub, install the requirements. For this, just run the command (All command ran on MacOS).

pip -r install requirements.txt

This command will install all the packages mentioned in the requirements.txt.

Now, create a database of our flask web app.

PostgreSQL

Install PostgreSQL if you don’t have it. Once installed , PostgreSQL creates a default user for you i.e. ‘postgres’.

To create the database, you need to log in as the user and password must be set during the installation process of PostgreSQL. After running this command, enter your password.

psql -U postgres

Let’s create a database named flask_project.

postgres=##  CREATE DATABASE flask_project;

After creating a database we will make a fruits table in which we have three columns — id, fruit, quantity

CREATE TABLE fruits(
id SERIAL PRIMARY KEY,
fruit VARCHAR(255),
quantity VARCAR(255));

Now, test the application by running the command

python app.py

You will see a screen like below and it has all the instructions. To request a server you can use Postman or curl command.

Image for post

#flask #docker #python #database #azure

Deploying CRUD Flask Web App With Docker on Azure
8.80 GEEK