Weather app using Django | Python Read Courses Practice Jobs Improve Improve Improve Like Article Like Save Article Save Report issue Report In this tutorial, we will learn how to create a Weather app that uses Django as backend. Django provides a Python Web framework based web framework that allows rapid development and clean, pragmatic design. Basic Setup – Change directory to weather â cd weather Start the server – python manage.py runserver To check whether the server is running or not go to a web browser and enter http://127.0.0.1:8000/ as URL. Now, you can stop the server by pressing ctrl-c Implementation : python manage.py startapp main Goto main/ folder by doing : cd main and create a folder with index.html file: templates/main/index.html Open the project folder using a text editor. The directory structure should look like this : Now add main app in settings.py Edit urls.py file in weather : from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('main.urls')), ] edit urls.py file in main : from django.urls import path from . import views urlpatterns = [ path('', views.index), ] edit views.py in main : from django.shortcuts import render # import json to load json data to python dictionary import json # urllib.request to make a request to api import urllib.request def index(request): if request.method == 'POST': city = request.POST['city'] ''' api key might be expired use your own api_key place api_key in place of appid ="your_api_key_here " ''' # source contain JSON data from API source = urllib.request.urlopen( 'http://api.openweathermap.org/data/2.5/weather?q =' + city + '&appid; = your_api_key_here').read() # converting JSON data to a dictionary list_of_data = json.loads(source) # data for variable list_of_data data = { "country_code": str(list_of_data['sys']['country']), "coordinate": str(list_of_data['coord']['lon']) + ' ' + str(list_of_data['coord']['lat']), "temp": str(list_of_data['main']['temp']) + 'k', "pressure": str(list_of_data['main']['pressure']), "humidity": str(list_of_data['main']['humidity']), } print(data) else: data ={} return render(request, "main/index.html", data) You can get your own API key from : Weather API Navigate to templates/main/index.html and edit it: link to index.html file Make migrations and migrate it: python manage.py makemigrations python manage.py migrate now let’s run the server to see your weather app. python manage.py runserver Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 25 May, 2022 Like Article Save Article Previous How to Create an App in Django ? Next Django Sign Up and login with confirmation Email | Python Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Create a Weather app using Flask | Python Weather App in Python using Tkinter module Find current weather of any city using OpenWeatherMap API in Python Python | Real time weather detection using Tkinter Scraping Weather prediction Data using Python and BS4 Get Live Weather Desktop Notifications Using Python Create a GUI for Weather Forecast using openweathermap API in Python Implementing Weather Forecast using Facade Design Pattern in Python Scraping weather data using Python to get umbrella reminder on email Building A Weather CLI Using Python Complete Tutorials Python API Tutorial: Getting Started with APIs Advanced Python Tutorials Python Automation Tutorial OpenAI Python API - Complete Guide Pandas AI: The Generative AI Python Library Like itsvinayak Follow Article Tags : Django-Projects Python Django Python Practice Tags : python Additional Information Current difficulty : Medium Vote for difficulty : Easy Normal Medium Hard Expert