This boilerplate project demonstrates how to render ReactJS components in a Flask & FastAPI web application using Jinja2.
This project demonstrates how to integrate ReactJS with a Flask & FastAPI web application using Jinja2. The core concept is to copy the static build output from the ReactJS project into the static resources folder of the Spring Boot application. React components are rendered by attaching multiple root elements to corresponding HTML DOM nodes, each identified by an section-*
prefix.
- Backend
- Flask
- FastAPI
- Jinja2
- Frontend
- React
- TypeScript
- Python 3.10+
- Node 20+
- react-common
- A common React project that copies its build output to both
flask-react
andfastapi-react
.
- A common React project that copies its build output to both
- flask-react
- A Python-based Flask project that uses the build output from
react-common
.
- A Python-based Flask project that uses the build output from
- fastapi-react
- A Python-based FlaskAPI project that uses the build output from
react-common
.
- A Python-based FlaskAPI project that uses the build output from
You can run either the Flask or FastAPI project, depending on your preference.
npm install -g yarn # If yarn is not installed
cd react-common
yarn install
yarn build
python3 -m venv .venv
source .venv/bin/activate
- Default server port: 5000
cd flask-react
pip3 install -r requirements.txt
python3 main.py
- Default server port: 5000
cd fastapi-react
pip3 install -r requirements.txt
python3 main.py