A collection of mini web apps that demonstrate core Flask concepts — routing, templates, forms, API integration, and environment variable management.
| Page | Route | Concepts |
|---|---|---|
| Hello | /hello, /hello/<name> |
Dynamic routing, template variables |
| AI Assistant | /ai |
Form POST, OpenAI API, .env secrets |
| Message Board | /messages |
GET & POST to external API, flash messages |
| Weather | /weather |
Form input → API call, API key management |
| Astronauts | /astronauts |
Simple GET API, JSON parsing, table rendering |
git clone https://github.com/OIM3640/webapp-demo.git
cd webapp-demopip install -r requirements.txtCopy the example file and fill in your API keys:
cp .env.example .envEdit .env with your keys:
SECRET_KEY=any-random-string-here
OPENAI_API_KEY=sk-...
OPENWEATHER_API_KEY=your-key-from-openweathermap.org
- OpenAI API key: provided via Canvas
- OpenWeather API key: sign up free at openweathermap.org
flask run --debugOpen http://127.0.0.1:5000 in your browser.
webapp-demo/
├── app.py # Flask application (routes and logic)
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
├── static/
│ └── style.css # Stylesheet
├── templates/
│ ├── base.html # Base template (nav + layout)
│ ├── index.html # Homepage
│ ├── hello.html # Hello page
│ ├── ai.html # AI assistant
│ ├── messages.html # Message board
│ ├── weather.html # Weather lookup
│ ├── astronauts.html # Astronauts in space
│ └── 404.html # Custom error page
└── docs/
├── deploy-render.md # Render deployment guide
└── deploy-pythonanywhere.md # PythonAnywhere deployment guide
- Template inheritance —
base.htmldefines the layout; other templates extend it with{% extends "base.html" %} - Static files — CSS loaded via
url_for('static', filename='style.css') - Form handling — GET to show form, POST to process input, redirect on error
- Flash messages — User feedback for errors and success
- API integration —
requestslibrary to call external APIs - Environment variables —
python-dotenvto load.envfile; secrets never hardcoded - Error handling — Custom 404 page, try/except around API calls