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的参数返回数据中文不乱码

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-01-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案