Create a Weather app using Flask | Python Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue 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. 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 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 and 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. Last Updated : 17 Sep, 2019 Like Article Save Article Previous Flask project - Create a Joke App with PyJokes Next Flask NEWS Application Using Newsapi Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Node.js Open Weather Map API for Weather Forecasts Create a Weather App with Forecast using React-Native Create a Weather app using React and Tailwind Weather app using Django | Python Weather App in Python using Tkinter module Weather app using Vanilla JavaScript Documenting Flask Endpoint using Flask-Autodoc Minify HTML in Flask using Flask-Minify Create a Real Time Currency Converter app using Flask | Python How to use Flask-Session in Python Flask ? Complete Tutorials JavaScript Examples CSS Examples HTML Examples Express.js Tutorial NodeJS Tutorial Like itsvinayak Follow Article Tags : Web technologies Python Web Technologies Practice Tags : python Additional Information Current difficulty : Easy Vote for difficulty : Easy Normal Medium Hard Expert