import json
from django.shortcuts import HttpResponse
from django.http import JsonResponse
from databases_models import models
from django.core import serializers
def serverhost_list(request):
host_list = models.GameServerVersion.objects.all()
host_list_json = serializers.serialize("json",host_list) #获取到的数据类型为字符串(str)
host_list_json = json.loads(host_list_json) #将字符串数据转成json类型
print(type(host_list_json))
result = {
"status": 0,
"message": host_list_json
}
return HttpResponse(json.dumps(result,ensure_ascii=False),content_type='application/json') #使用HttpResponse的参数返回数据中文不乱码