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