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


前言

都是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数据时中文出现乱码


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM