This project extends the Learning Journal progressive web app with a Flask backend that serves, stores, and mutates reflections inside backend/reflections.json. The UI continues to live in the templates/ + static/ folders while Flask powers API endpoints that feed content to the browser through the Fetch API.
- Flask 3 (Python 3.10+) serving HTML templates and JSON APIs
- JSON file persistence (
backend/reflections.json) - Vanilla JS Fetch API for CRUD actions
- Service worker + manifest for installable PWA behaviour
- Dynamic reflections list fetched from
/reflections - Add new entries via
/add_reflection - Delete any entry with the new
DELETE /reflections/<timestamp>route (extra backend-powered feature) - PWA install prompt, offline-first caching with network-first strategy for live reflections
.
├── flask_app.py # Main Flask entry point
├── backend/
│ └── reflections.json # JSON datastore
├── static/ # CSS, JS, images, manifest, service worker
└── templates/ # HTML views served by Flask
- Create and activate a virtual environment (recommended).
- Install dependencies:
pip install -r requirements.txt - Start Flask:
python flask_app.py - Visit
http://localhost:8000/journalto add and manage reflections.
| Method | Route | Description |
|---|---|---|
| GET | /reflections |
Returns the current reflections JSON payload. |
| POST | /add_reflection |
Validates and appends a new reflection to the JSON file. |
| PUT | /reflections/<timestamp> |
Updates fields on an existing reflection (title, reflection text, etc.). |
| DELETE | /reflections/<timestamp> |
Removes the reflection identified by its timestamp value. |
| GET | /reflections/search |
Filters reflections by query, week, or tech tag via query parameters. |
| GET | /healthz |
Lightweight health probe for uptime checks. |
All POST bodies must be JSON. Responses are JSON and include helpful error messages for invalid data.
- Upload / Clone: Push all files to GitHub, then pull them into your PythonAnywhere account (or upload a zip).
- Virtualenv: In PythonAnywhere bash console:
cd ~/mysite # or your project folder python3.10 -m venv venv source venv/bin/activate pip install -r requirements.txt
- WSGI config (
/var/www/<username>_pythonanywhere_com_wsgi.py):import sys path = '/home/<username>/mysite' if path not in sys.path: sys.path.append(path) from flask_app import app as application
- Static files: In the PythonAnywhere web tab, map the URL
/static/to/home/<username>/mysite/static/. - Reload app: Hit Reload in the web tab and browse to your site. The service worker, manifest, and fetch requests will now hit Flask on PythonAnywhere.
You can tail the error log in the web tab if anything fails (~/<username>.pythonanywhere.com.error.log).