我想转换json类型的数据,但是我收到了这个错误
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 contextservice.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>发布于 2020-07-20 13:53:49
看起来液滴不是一个清单,它是一个小弟弟。
尝尝这个
for i in droplets['projects']:
droplet_list.append(i)https://stackoverflow.com/questions/62970841
复制相似问题