django 使用HttpResponse返回json数据为中文

之前我用django一般用JsonResponse来返回json数据格式

但是发现返回中文的时候会乱码

from django.http import JsonResponse
def test(request):
    result = {"status":"错误","data":"","city":"北京"}
    return return JsonResponse(result)

这种方式返回简单,但是中文会乱码

 

 

现在改成用HttpResponse来返回,显示中文成功

from django.http import HttpResponse
import json
def test(request): result = {"status":"错误","data":"","city":"北京"} #json返回为中文 return HttpResponse(json.dumps(result,ensure_ascii=False),content_type="application/json,charset=utf-8")
posted @ 2018-10-11 16:35  繁华博客  阅读(15106)  评论(4编辑  收藏  举报