import requests from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from .models import City # Create your views here. def user_homepage(request): url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=38e4fec38e509c018629074ac1754906' city = 'London' cities = City.objects.all() weather_data = [] for city in cities: r = requests.get(url.format(city)).json() city_weather = { 'city': city.name, 'temperature' : r['main']['temp'], 'description' : r['weather'][0]['description'], 'icon' : r['weather'][0]['icon'], } weather_data.append(city_weather) result = {'city_weather' : city_weather} return render(request, 'userhomepage.html', result) # def post(self, request):
return reverse(bla, blabla)
class Author(models.Model): ... return reverse('author-detail', args=[str(self.id)])
{% for title in books reversed %}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)