Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我开始犯错误了_Python_Python 3.x_Django_Django Views - Fatal编程技术网

Python 我开始犯错误了

Python 我开始犯错误了,python,python-3.x,django,django-views,Python,Python 3.x,Django,Django Views,这是my views.py文件: url = "https://covid-193.p.rapidapi.com/statistics" headers = { 'x-rapidapi-key': "c5e4f10fa8msh519e24367741e55p1dcabajsn27df4eda14e0", 'x-rapidapi-host': "covid-193.p.rapidapi.com" } respons

这是my views.py文件:

url = "https://covid-193.p.rapidapi.com/statistics"
headers = {
    'x-rapidapi-key': "c5e4f10fa8msh519e24367741e55p1dcabajsn27df4eda14e0",
    'x-rapidapi-host': "covid-193.p.rapidapi.com"
    }
response = requests.request("GET", url, headers=headers).json()
def home(request):
    noofresults = int(response['results'])
    mylist = []
    for x in range(0,noofresults):
        mylist.append(response['response'][x]['country'])    
    if request.method=='POST':
        selectedcountry= request.POST['selectedcountry']
        # noofresults = int(response['results'])
        for x in range(0,noofresults):
            if selectedcountry==response['response'][x]['country']:
                new = response['response'][x]['cases']['new']
                active = response['response'][x]['cases']['active']
                critical = response['response'][x]['cases']['critical']
                recoverd = response['response'][x]['cases']['recovered']
                total = response['response'][x]['cases']['total']
                deaths = int(total)-int(active) - int(recoverd)    
        context = {'selectedcountry':selectedcountry,'mylist':mylist, 'new':new, 'active':active, 'critical':critical, 'recoverd':recoverd, 'total':total, 'deaths':deaths}
        return render(request,'home.html',context)                
    context = {'mylist': mylist}
    return render(request, 'home.html',context)
我在选择国家/地区后遇到的错误是:

赋值前引用的/局部变量“new”处的UnboundLocalError


在循环之前初始化新的、活动的、严重的、已恢复的、总计的、死亡人数在循环之前初始化新的、活动的、严重的、已恢复的、总计的、死亡人数