A fully functional Django-based Weather Application that allows users to search for any city and view real-time weather information using WeatherAPI.
The project follows clean architecture, secure API key handling, and robust exception handling.
- Project Overview
- Key Features
- Tech Stack
- System Architecture
- Project Structure
- API Integration
- Environment Variables (.env)
- Installation & Setup
- Exception Handling
- Frontend UI
- Security Best Practices
- Testing Scenarios
- Future Enhancements
- Contributing
- License
- Author
This is a server-side rendered Django web application that fetches real-time weather data based on a user-entered city name.
- π‘οΈ Current temperature
- π₯οΈ Weather condition
- π§ Humidity level
- π¬οΈ Wind speed
- πΌοΈ Weather icon
The application is designed with:
- Clean UI
- Secure API handling
- Graceful failure recovery
- π Search weather by city name
- π‘οΈ Temperature in Celsius
- π₯οΈ Condition with icon
- π§ Humidity percentage
- π¬οΈ Wind speed (km/h)
- π¨ Bootstrap-based UI
- π Secure API key handling via
.env β οΈ Robust exception handling- π± Fully responsive design
- Python 3.10+
- Django 4+
- Requests
- HTML5
- CSS3
- Bootstrap 5
- WeatherAPI (
current.jsonendpoint)
- python-dotenv
User Browser
β
HTML Form (POST)
β
Django View
β
WeatherAPI (External API)
β
JSON Response
β
Django Template Rendering
β
User Interface
weather_project/
β
βββ manage.py
βββ .env
βββ .gitignore
β
βββ weather_project/
β βββ __init__.py
β βββ settings.py
β βββ urls.py
β βββ asgi.py
β βββ wsgi.py
β
βββ weather_app/
β βββ __init__.py
β βββ views.py
β βββ urls.py
β βββ templates/
β βββ index.html
β
βββ README.md
WeatherAPI β Current Weather Endpoint
http://api.weatherapi.com/v1/current.json
| Parameter | Description |
|---|---|
| key | API key |
| q | City name |
| aqi | Air quality (yes/no) |
?key=API_KEY&q=London&aqi=no
- Prevents API key exposure
- Keeps secrets out of GitHub
- Follows industry standards
WEATHER_API_KEY=your_api_key_herefrom dotenv import load_dotenv
load_dotenv()git clone https://github.com/your-username/django-weather-app.git
cd django-weather-apppython -m venv venvActivate:
Windows:
venv\Scripts\activatemacOS/Linux:
source venv/bin/activatepip install django requests python-dotenvpython manage.py migratepython manage.py runserver- Open in browser:
http://127.0.0.1:8000/
| Scenario | Handling |
|---|---|
| Invalid city | API error message |
| No internet | Connection error handled |
| API timeout | Timeout exception |
| Invalid API key | HTTP 401 handling |
| Server error | Graceful fallback |
| Invalid JSON | KeyError handling |
All errors are displayed as user-friendly Bootstrap alerts.
- Gradient background
- Card-based weather display
- Bootstrap alerts
- Responsive for mobile & desktop
- API key stored in
.env .envadded to.gitignore- No hard-coded secrets
- CSRF protection enabled
- Input validation handled
| Test Case | Result |
|---|---|
| Valid city | Weather displayed |
| Invalid city | Error message |
| API down | Graceful failure |
| Internet off | No crash |
| First load | Clean UI |
- 7-day weather forecast
- Dark mode
- AJAX-based search
- Auto-detect user location
- Docker deployment
- Weather analytics dashboard
- Fork repository
- Create feature branch
- Commit changes
- Open pull request
This project is licensed under the MIT License.
Shreyas K G Python | Django | Web Development
β If you find this project helpful, please give it a star!