I am trying to make Django view that will give JSON responce with earliest and latest objects. But unfotunately it fails to work with this error.
我正在尝试制作Django视图,它将使JSON响应最早和最新的对象。但不幸的是,它无法解决此错误。
'str' object has no attribute '_meta'
I have other serialization and it works.
我有其他序列化,它的工作原理。
Here is the code.
这是代码。
def get_calendar_limits(request):
result = serializers.serialize("json", Session.objects.aggregate(Max('date'), Min('date')), ensure_ascii=False)
return HttpResponse(result, mimetype="application/javascript")
Thanks a lot beforehand.
非常感谢,事先。
3 个解决方案
#1
Take a look at the following:
看看以下内容:
objects= Session.objects.aggregate(Max('date'), Min('date'))
print [ type[o] for o in objects ]
result = serializers.serialize("json", objects, ensure_ascii=False)
You might want to just run the above in interactive Python as an experiment.
您可能希望在交互式Python中运行上述内容作为实验。
What type are your objects? Is that type serializable?
你的物品是什么类型的?这种类型是否可序列化?
#2
I get the same error when trying to serialize an object that is not derived from Django's Model
尝试序列化不是从Django模型派生的对象时,我得到了同样的错误
#3
Python has "json" module. It can 'dumps' and 'loads' function. They can serialize and deserialize accordingly.
Python有“json”模块。它可以“转储”和“加载”功能。他们可以相应地序列化和反序列化。
#1
Take a look at the following:
看看以下内容:
objects= Session.objects.aggregate(Max('date'), Min('date'))
print [ type[o] for o in objects ]
result = serializers.serialize("json", objects, ensure_ascii=False)
You might want to just run the above in interactive Python as an experiment.
您可能希望在交互式Python中运行上述内容作为实验。
What type are your objects? Is that type serializable?
你的物品是什么类型的?这种类型是否可序列化?
#2
I get the same error when trying to serialize an object that is not derived from Django's Model
尝试序列化不是从Django模型派生的对象时,我得到了同样的错误
#3
Python has "json" module. It can 'dumps' and 'loads' function. They can serialize and deserialize accordingly.
Python有“json”模块。它可以“转储”和“加载”功能。他们可以相应地序列化和反序列化。