0
我想從Web API檢索一些數據,因爲我想在瀏覽器中顯示它和我想通過分配這些數據來操作它給一個變量,這樣我就可以操縱數據,但我得到的錯誤:如何解決'字典'對象沒有屬性'_meta'
'dict' object has no attribute '_meta'.
查看
from django.core import serializers
from rest_framework.views import APIView
from rest_framework.response import Response
import json, urllib.request
from django.views.generic import View
from django.http import JsonResponse
def get_data(request, *args, **kwargs):
with urllib.request.urlopen("http://10.61.202.98:8081/T/ansdb/api/rows/dev/tickets?id=1003611",timeout=10) as url:
response_data = json.loads(url.read().decode())
response_data_serialized = serializers.serialize('json',response_data)
return JsonResponse(response_data_serialized, safe=False)
網址
urlpatterns = [
url(r'^$', views.index, name='index'), # home
url(r'^statistics/$', views.statistics, name='statistics'),
url(r'^statistics/data$', get_data, name='get_data'),]
,我要檢索的數據格式如下:
[{
id: 100361324,
Aging_Deferred_Transferred: "",
Aging_Open_Issue: "",
Aging_Un_investigated_Issue: "",
CreatedBy: "[email protected]",
DeltaQD: null,
DeltaQDBadAttempts: null,
Escalation_Category: "",
Golden_Cluster: "",
Incident_DateTime: "2017-02-01
Week: "8",
Weekend_Flag: "Yes"
}]
一些鏈接我讀了Django JSON:: 'dict' object has no attribute '_meta'和Django1.9: 'function' object has no attribute '_meta'但在這些鏈接的解決方案不適合我的問題。
任何關於如何解決這個問題的幫助是值得歡迎的。
預先感謝您。
您是否打印response_data?它是字典還是json? – Sagar
當我將它打印爲print(response_data)時,我得到一個JSON,但是當我嘗試打印response_data時,沒有打印出來。 –