A simple and elegant Django-based web application that fetches and displays real-time weather data from the OpenWeatherMap API.
This project allows users to get the current weather information for any city in the world. It's built with Django and uses the OpenWeatherMap API to fetch real-time data. This application is a great starting point for anyone looking to build a web app with Django and integrate with a third-party API.
- Real-Time Weather Data: Get up-to-date weather information.
- Search by City: Users can search for any city to get weather details.
- Detailed Information: Displays temperature, humidity, pressure, weather conditions, and coordinates.
- User-Friendly Interface: A clean and simple UI for easy use.
- Error Handling: Gracefully handles invalid city names and API errors.
- Python 3.8+
- Django 4+
- Requests
-
Clone the Repository:
git clone [https://github.com/your-username/weather-api.git](https://github.com/your-username/weather-api.git) cd weather-api -
Create a Virtual Environment:
python -m venv venv
Activate the environment:
- Windows:
venv\Scripts\activate - macOS/Linux:
source venv/bin/activate
- Windows:
-
Install Dependencies:
pip install -r requirements.txt
(Note: You'll need to create a
requirements.txtfile. See the section below.) -
Get Your API Key:
- Go to OpenWeatherMap and create a free account.
- Navigate to the "API keys" tab and get your API key.
-
Set Up Environment Variables:
- In
wheatherapp/settings.py, add the following line at the end of the file:WEATHER_API_KEY = 'your_openweathermap_api_key'
- Important: For a production environment, it's recommended to use environment variables to keep your API key secure.
- In
-
Apply Migrations:
python manage.py migrate
-
Run the Server:
python manage.py runserver
The application will be running at
http://127.0.0.1:8000/.
Create a file named requirements.txt in the root of your project and add the following lines: