键错误位于/项目/

2024-06-13 13:47:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想转换json类型的数据,但我收到了这个错误,请问我的代码中的错误在哪里,在我的终端中,我收到了两个问题,在这个链接“droplet_list.append(drops[i])”中,在这个页面中查看“'drops':get_drops()”

json类型的数据:

 {
"projects": [
    {
        "id": 173,
        "name": "test",
        "identifier": "a",
        "description": "a",
        "status": 1,
        "is_public": true,
        "created_on": "2020-07-12T05:17:20Z",
        "updated_on": "2020-07-12T05:17:20Z"
    },

views.py:

class GetDroplets(TemplateView):
template_name = 'blog/home.html'

def get_context_data(self, *args, **kwargs):
    context = {
        'droplets' : get_droplets(),
    }
    return context

service.py:

 def get_droplets():

headers = {'Content-type': 'application/json',
'PRIVATE-TOKEN': '',
'Authorization': ''
}

url='http://172.16.0.111/api/v4/projects/'
url_redmine='http://172.16.0.112:3000/projects.json/'
r = requests.get(url, headers=headers)
r = requests.get(url_r, headers = {'Authorization': 'Basic =='})

droplets = r.json()
print(droplets)
droplet_list = []


for i in range(len(droplets)):
    droplet_list.append(droplets[i])
return droplet_list
return JsonResponse({'droplets':droplets}, content_type='application/json')
**table.html**:
           
                  <tr>
                  
                    <th scope="col">Id</th>
                    <th scope="col">Project Name</th>
                    <th scope="col">Identifiat Project</th>
                   
                   </tr>
              </thead>
    <tbody>
      {% for droplet in  droplets %}
    
      <tr> 
                  <td>{{ droplet.id }} </td>
                  <td>{{ droplet.name}}</td>
                  <td>{{ droplet.identifier }}</td>




      

Tags: namejsonurlgetreturncontexttrlist