报错 AttributeError: ‘Request’ object has no attribute ‘is_xhr’
解决方法
1)查看jsonify原函数
def jsonify(*args, **kwargs):
'''This function's response will be pretty printed if it was not requested
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.
.. versionadded:: 0.2
'''
indent = None
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] \
and not request.is_xhr:
indent = 2
return current_app.response_class(dumps(dict(*args, **kwargs),
indent=indent),
mimetype='application/json')
发现 将JSONIFY_PRETTYPRINT_REGULAR配置为False就能解决.
2) 解决如下:
在flask配置文件配置:
JSONIFY_PRETTYPRINT_REGULAR = False
返回的中文编码不对
解决方法:
在flask配置文件配置:
JSON_AS_ASCII = False # 支持中文
flask的jsonify序列化dict后的结果会自动根据key的下标升序排列,希望dict原样返回的方法
解决方法:
在flask配置文件配置:
JSON_SORT_KEYS = False # 不使用jsonify默认排序功能