Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌦️ Django Weather Application

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.


πŸ“Œ Table of Contents

  1. Project Overview
  2. Key Features
  3. Tech Stack
  4. System Architecture
  5. Project Structure
  6. API Integration
  7. Environment Variables (.env)
  8. Installation & Setup
  9. Exception Handling
  10. Frontend UI
  11. Security Best Practices
  12. Testing Scenarios
  13. Future Enhancements
  14. Contributing
  15. License
  16. Author

🌍 Project Overview

This is a server-side rendered Django web application that fetches real-time weather data based on a user-entered city name.

Users can view:

  • 🌑️ Current temperature
  • πŸŒ₯️ Weather condition
  • πŸ’§ Humidity level
  • 🌬️ Wind speed
  • πŸ–ΌοΈ Weather icon

The application is designed with:

  • Clean UI
  • Secure API handling
  • Graceful failure recovery

✨ Key Features

  • πŸ”Ž 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

πŸ› οΈ Tech Stack

Backend

  • Python 3.10+
  • Django 4+
  • Requests

Frontend

  • HTML5
  • CSS3
  • Bootstrap 5

API

  • WeatherAPI (current.json endpoint)

Utilities

  • python-dotenv

🧠 System Architecture

User Browser
   ↓
HTML Form (POST)
   ↓
Django View
   ↓
WeatherAPI (External API)
   ↓
JSON Response
   ↓
Django Template Rendering
   ↓
User Interface

πŸ“‚ Project Structure

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

🌐 API Integration

API Used

WeatherAPI – Current Weather Endpoint http://api.weatherapi.com/v1/current.json

Request Parameters

Parameter Description
key API key
q City name
aqi Air quality (yes/no)

Example Request

?key=API_KEY&q=London&aqi=no

πŸ” Environment Variables (.env)

Why use .env?

  • Prevents API key exposure
  • Keeps secrets out of GitHub
  • Follows industry standards

.env file (Project Root)

WEATHER_API_KEY=your_api_key_here

Load .env in settings.py

from dotenv import load_dotenv
load_dotenv()

πŸ“¦ Installation & Setup

1️⃣ Clone Repository

git clone https://github.com/your-username/django-weather-app.git
cd django-weather-app

2️⃣ Create Virtual Environment

python -m venv venv

Activate:

Windows:

venv\Scripts\activate

macOS/Linux:

source venv/bin/activate

3️⃣ Install Dependencies

pip install django requests python-dotenv

4️⃣ Apply Migrations

python manage.py migrate

5️⃣ Run Development Server

python manage.py runserver
  • Open in browser: http://127.0.0.1:8000/

⚠️ Exception Handling

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.

🎨 Frontend UI

  • Gradient background
  • Card-based weather display
  • Bootstrap alerts
  • Responsive for mobile & desktop

πŸ”’ Security Best Practices

  • API key stored in .env
  • .env added to .gitignore
  • No hard-coded secrets
  • CSRF protection enabled
  • Input validation handled

πŸ§ͺ Testing Scenarios

Test Case Result
Valid city Weather displayed
Invalid city Error message
API down Graceful failure
Internet off No crash
First load Clean UI

πŸš€ Future Enhancements

  • 7-day weather forecast
  • Dark mode
  • AJAX-based search
  • Auto-detect user location
  • Docker deployment
  • Weather analytics dashboard

🀝 Contributing

  • Fork repository
  • Create feature branch
  • Commit changes
  • Open pull request

πŸ“œ License

This project is licensed under the MIT License.

πŸ‘¨β€πŸ’» Author

Shreyas K G Python | Django | Web Development

⭐ If you find this project helpful, please give it a star!

About

A Django web application that fetches and displays real-time weather data using WeatherAPI.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages