- Serve an HTML page using Flask
- Create a Flask API route that returns JSON
- Connect frontend JavaScript to backend Flask using fetch()
- Structure a full-stack project with clear separation between client and server
.
├── client/
│ ├── index.html
│ ├── styles.css
│ └── script.js
├── server/
│ ├── app.py
│ ├── store.py
│ └── __init__.py
├── tests/
│ └── test_app.py
├── Pipfile or requirements.txt
└── README.md
- Install dependencies:
Using Pipenv:
pipenv install
pipenv shell
Using pip and venv:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
- Run the server:
python server/app.py
- Open your browser and go to:
http://localhost:5000/
- Complete the backend route in
app.py
to serve theindex.html
file. - Add a second route that returns JSON data at
/api/data
. - Use
store.py
to generate the data. - Make the frontend (in
script.js
) fetch data from the backend. - Run
pytest
and pass all the tests intest_app.py
.
Good luck!