Django - HttpResponse返回JSON数据时中文编码为Unicode

时间:2021-05-31 20:23:49

前言

都是json模块搞的鬼!

   def post(self, request):
        print("get ajax")
        if request.is_ajax:
            print(request.POST)
            article_type = request.POST.get('article_type')
            title = request.POST.get('title')
            summary = request.POST.get('summary')
            publish = request.POST.get('publish')
            editor = request.POST.get('editor')
            print("article_type:", article_type,
                  "title:", title,
                  "summary:", summary,
                  "publish:", publish,
                  "editor:", editor)
            return HttpResponse(json.dumps("成功!",ensure_ascii=False), content_type='application/json', charset='utf-8')

 

博客搬运地址

  1. django 使用HttpResponse返回json数据为中文
  2. nginx+django httpresponse返回中文编码问题
  3. Django学习问题——解决返回JSON数据时中文出现乱码