AttributeError: 'tuple' object has no attribute '_Meta'ソリューション
エラーメッセージの表示:メタグループオブジェクトに'_がありませんmeta’という属性?次は私のコードです
データを照会できますが、データをシーケンス化するときにエラーが発生しました.伝達のタイプが違うのか、それとも何なのか.djangoのシーケンス化クラスはdjangoにある.coreの下のserializersフォルダの中、base.pyファイルには、シーケンサと逆シーケンサのベースクラスといくつかの異常が定義されています.init.pyファイルは、フォーマットに基づいて対応するシーケンサなどを選択する方法を定義するinit.py
ソリューション:import json
return JsonResponse(json.dumps(data), safe=True)
# json
import json
from django.core import serializers
from django.http import JsonResponse
def ajax_jz(request):
# ,
cur = connection.cursor()
# SQl ( ( ))
sql ='select j.id,h.GPS,j.SystemStatus,j.YuLiu3 from tower_project_jizhan j inner join tower_project_hjinformation h on j.SheBei_Code= h.SheBei_Code'
#
cur.execute(sql)
#
resultData = cur.fetchall()
for item in resultData:
print(item)
# , JSON
ajax_bmsValue = serializers.serialize("json", resultData)
#
return HttpResponse(ajax_bmsValue)
データを照会できますが、データをシーケンス化するときにエラーが発生しました.伝達のタイプが違うのか、それとも何なのか.djangoのシーケンス化クラスはdjangoにある.coreの下のserializersフォルダの中、base.pyファイルには、シーケンサと逆シーケンサのベースクラスといくつかの異常が定義されています.init.pyファイルは、フォーマットに基づいて対応するシーケンサなどを選択する方法を定義するinit.py
def get_deserializer(format):
if not _serializers:
_load_serializers()
if format not in _serializers:
raise SerializerDoesNotExist(format)
return _serializers[format].Deserializer
def serialize(format, queryset, **options):
"""
Serialize a queryset (or any iterator that returns database objects) using
a certain serializer.
"""
s = get_serializer(format)()
s.serialize(queryset, **options)
return s.getvalue()
ソリューション:import json
return JsonResponse(json.dumps(data), safe=True)
def ajax_jz(request):
#
cur = connection.cursor()
sql ='select j.id,h.GPS,j.SystemStatus,j.YuLiu3 from tower_project_jizhan j inner join tower_project_hjinformation h on j.SheBei_Code= h.SheBei_Code'
cur.execute(sql)
resultData = cur.fetchall()
for item in resultData:
print(item)
# json.dumps
return HttpResponse(json.dumps(resultData))
#
cur.close()