最近在学习python来充实自己,在学习过程会遇到很多奇怪的问题。
会不定时记录一下,也希望能帮助到其他人
在调用html向其传值时,会出现以下问题
- python代码
return render(request, 'index.html', context)
- 错误内容
修改如下
- 修改前:
def temp_here(self):
location = geocoder.ip('me').latlng
endpoint = "https://api.open-meteo.com/v1/forecast"
api_request = f"{endpoint}?latitude={location[0]}&longitude={location[1]}&hourly=temperature_2m"
now = datetime.now()
hour = now.hour
meteo_data = requests.get(api_request).json()
temp = meteo_data['hourly']['temperature_2m'][hour]
context = {'temp': temp}
return render(request, 'index.html', context)
- 修改后:
def temp_here(**request**):
location = geocoder.ip('me').latlng
endpoint = "https://api.open-meteo.com/v1/forecast"
api_request = f"{endpoint}?latitude={location[0]}&longitude={location[1]}&hourly=temperature_2m"
now = datetime.now()
hour = now.hour
meteo_data = requests.get(api_request).json()
temp = meteo_data['hourly']['temperature_2m'][hour]
context = {'temp': temp}
return render(request, 'index.html', context)
虽然错误很低级,希望能帮助初学python的小伙伴
天行健君子以自强不息、地势坤君子以厚德载物!!!
END