This is a minimal sample Flask and React starter code that demonstrates how both frameworks can be used together in a single page web Application.
The code is based on https://github.com/dternyak/React-Redux-Flask and https://github.com/creativetimofficial/material-dashboard-react
- Clone the reponsitory
git clone https://github.com/jeffreymew/Flask-React-Postgres.git
cd flask-react-postgres
- Create and activate a virtual environment
In Bash
python3 -m venv venv
source venv/bin/activate
In Powershell
py -3 -m venv env
env\scripts\activate
In Powershell
py -3 -m venv env
env\scripts\activate
- Install requirements.txt
pip install -r requirements.txt
- Import the project folder into VS Code
code .
- Build the react.js front-end.
npm install
npm run build
- Create the SQL database
cd ..
python manage.py create_db
- Start the Flask server
python manage.py runserver
- Check
localhost:5000
in your browser to view the web application.
-
Go to the extensions tab on VS Code
-
Install the recommended extensions that show up (App Service Extension, Python Extension)
-
Reload the window and navigate to the Azure tab on the left
-
Access Azure services through (1) Guest Mode, (2) Creating a free Azure account or (3) signing into Azure with an existing account
-
Create an App Service instance with the parameters of a linux system with a Python runtime
-
Create a PostgreSQL database with Azure Database for Postgres and connect it to the App Service instance
-
Navigate to the Azure portal for the Azure Database for Postgres instance and allow incoming connections to the instance for everyone
-
Navigate to the Azure portal for the App service instance that was just created, and under the "Application Settings" tab and uneder the "Runtime" section, set the "startup file" parameter to be "startup.txt"
-
Again under the "Application Settings" tab and under the "Application Settings" section, add a new environment variable for the Postgres
-
Deploy the code to your newly created App Service instance
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.