/'处的类型错误;模型库&x27;对象不可编辑…如何在django中解决此问题
/'ModelBase'对象处的TypeError不可编辑…..如何在django中解决此问题 这是我的models.py:/'处的类型错误;模型库&x27;对象不可编辑…如何在django中解决此问题,django,weather-api,Django,Weather Api,/'ModelBase'对象处的TypeError不可编辑…..如何在django中解决此问题 这是我的models.py: from django.db import models class City(models.Model): name = models.CharField(max_length=30) def __str__(self): return self.name class Meta: verbose_name_p
from django.db import models
class City(models.Model):
name = models.CharField(max_length=30)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = 'cities'
views.py:
import requests
from django.shortcuts import render
from . models import City
def home(request):
url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=37dcd1bbdc2216925ebb043a870105a6'
cities = City.objects.all()
weather_data = []
for city in City:
city_weather = requests.get(url.format(city)).json()
weather = {
'city' : city,
'temperature' : city_weather['main']['temp'],
'description' : city_weather['weather'][0]['description'],
'icon' : city_weather['weather'][0]['icon']
}
weather_data.append(weather)
context = {'weather_data' : weather_data}
return render(request,'home.html',context)
请帮我解决这个问题,因为我是Django的初学者。在您的主页视图中,城市中城市的
行应该是城市中城市的