0% found this document useful (0 votes)
6 views1 page

Wethaerapi

Uploaded by

Megha basvaraju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Wethaerapi

Uploaded by

Megha basvaraju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

5.

Current Weather Display

Description: Display current weather information for a prede ned location.

Key Concepts:

• URL routing
• Views
• Templates
• Using a weather API
View Example:

import requests

def current_weather(request):
response = requests.get('http://api.weatherapi.com/v1/
current.json?key=YOUR_API_KEY&q=London')
weather_data = response.json()
temperature = weather_data['current']['temp_c']
condition = weather_data['current']['condition']['text']
return render(request, 'timeapp/current_weather.html',
{'temperature': temperature, 'condition': condition})

HTML Template:

<div class="container text-center mt-5">


<h1 class="display-4">Current Weather</h1>
<p class="lead">Temperature: {{ temperature }}°C</p>
<p class="lead">Condition: {{ condition }}</p>
</div>
fi

You might also like