- 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 shellUsing 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.pyto serve theindex.htmlfile. - Add a second route that returns JSON data at
/api/data. - Use
store.pyto generate the data. - Make the frontend (in
script.js) fetch data from the backend. - Run
pytestand pass all the tests intest_app.py.
Good luck!