python - flask-restful 中文返回的响应变成了 unicode literal
问题描述
下面的示例代码,运行在 Python 2.7 环境
pip install flask-restful flask
# -*- coding:utf-8 -*-from flask import Flaskfrom flask_restful import Api, Resource, reqparse, marshal_with, fieldsclass Greetings(Resource): def get(self, message=None):message = ’中文한국어’greeting = ’You have received a message: {0}’.format(message) if message else ’zzzzzzz......’return greeting, 200app = Flask(__name__)api = Api(app)api.add_resource(Greetings, ’/radio/’, ’/radio/<message>’)if __name__ == ’__main__’: app.run(port=8000,debug=True)
这是运行的结果:
问题解答
回答1:指定 RESTFUL_JSON 配置项:
app = Flask(__name__)app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))
相关文章:
1. Python爬虫如何爬取span和span中间的内容并分别存入字典里?2. mysql - 把一个表中的数据count更新到另一个表里?3. 请教使用PDO连接MSSQL数据库插入是乱码问题?4. mysql - 分库分表、分区、读写分离 这些都是用在什么场景下 ,会带来哪些效率或者其他方面的好处5. visual-studio - Python OpenCV: 奇怪的自动补全问题6. 视频文件不能播放,怎么办?7. mysql 查询身份证号字段值有效的数据8. linux - Ubuntu下编译Vim8(+python)无数次编译失败9. node.js - nodejs开发中常用的连接mysql的库10. python - 爬虫模拟登录后,爬取csdn后台文章列表遇到的问题
