最近在学习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
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐