前言
django 查询到的结果,返回到页面上显示unicode编码,怎样将编码转换成中文呢?
数据库含有中文
通过上篇构建的方法,返回到的结果如下:
中文显示的是unicode编码格式,查看JsonResponse源码介绍
解决方法
JsonResponse里面有个参数json_dumps_params,设置为json_dumps_params={‘ensure_ascii’:False}不进行转码,适用于上篇介绍的三种方法
修改后代码
返回的结果中文可以正常显示:
{"data": [{"user_name": "liushui", "psw": "123456", "mail": "123456@163.com"}, {"user_name": "liushui0", "psw": "12345", "mail": "123@qq.com"}, {"user_name": "liushui1", "psw": "123", "mail": "123456@qq.com"}, {"user_name": "liushui11", "psw": "123456", "mail": "897564"}, {"user_name": "流水", "psw": "1110", "mail": "110@qq.com"}, {"user_name": "流水11", "psw": "112", "mail": "111@qq.com"}]}