import json
from django.core import serializers
from django.http import HttpResponse, Http404
from menu.models import *
def Database(request):
if request.method == 'GET':
menus = Menu.objects.all()
return toJSON(serialize(menus))
def serialize(menus):
serialized = []
for obj in menus:
serialized.append(obj.serializer())
return serialized
def toJSON(menus, status=200):
j = json.dumps(menus, ensure_ascii=False)
return HttpResponse(j, status=status, content_type='application/json; charset=utf-8')
我views.py
喜欢这样,但它只返回[]
,我该如何解决?