Create a Weather app using Flask | Python Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Prerequisite : Flask installation Flask is a lightweight framework written in Python. It is lightweight because it does not require particular tools or libraries and allow rapid web development. today we will create a weather app using flask as a web framework. this weather web app will provide current weather updates of cities searched. Basic setup : Create a file and name it as weather.py Linux command to create a file touch weather.py Now, create a folder templates with a file name index.html Linux command to create a folder and a file mkdir templates && cd templates && touch index.html The project folder will look like : Editing files : Use your own API key from Weather API and place it in API variable. Now edit weather.py file. Python3 1== from flask import Flask, render_template, request # import json to load JSON data to a python dictionary import json # urllib.request to make a request to api import urllib.request app = Flask(__name__) @app.route('/', methods =['POST', 'GET']) def weather(): if request.method == 'POST': city = request.form['city'] else: # for default name mathura city = 'mathura' # your API key will come here api = api_key_here # source contain json data from api source = urllib.request.urlopen('http://api.openweathermap.org/data/2.5/weather?q =' + city + '&appid =' + api).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) return render_template('index.html', data = data) if __name__ == '__main__': app.run(debug = True) Navigate to templates/index.html and edit it: link to the index file. Now you can run the server to see the weather app - python weather.py Create Quiz Comment I itsvinayak Follow 2 Improve I itsvinayak Follow 2 Improve Article Tags : Python Web technologies Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like