如何在 Flask 的一行中 return json 响应?
How to return a json response in one line in flask?
我正在 flask 中编写一条路由来发送这个响应,我需要用一条实线发送这个 json 响应但是当我发送这个 json(因为长度)发送多行
@app.route("/dashboard", methods= ['GET','POST'])
def index():
.
.
.
response = {"iDisplayStart":1,"iDisplayLength":10,
"iTotalRecords":2,"iTotalDisplayRecords":2,"data":data_ne}
return jsonify(results)
当我在下方发送此 json 响应时 return
{
"iDisplayStart": 1,
"iDisplayLength": 10,
"iTotalRecords": 2,
"iTotalDisplayRecords": 2,
"data": [
{data_ne}]}
但我想像下面这样在单行中
{"iDisplayStart":1,"iDisplayLength":10,"iTotalRecords":2,"iTotalDisplayRecords":2,"data":data_ne}
有什么办法吗?感谢您的考虑。
你 运行 Flask 处于调试模式吗?尝试将 JSONIFY_PRETTYPRINT_REGULAR
环境变量设置为 false。来自 documentation:
The default output omits indents and spaces after separators. In debug mode or if JSONIFY_PRETTYPRINT_REGULAR is True, the output will be formatted to be easier to read.
我正在 flask 中编写一条路由来发送这个响应,我需要用一条实线发送这个 json 响应但是当我发送这个 json(因为长度)发送多行
@app.route("/dashboard", methods= ['GET','POST'])
def index():
.
.
.
response = {"iDisplayStart":1,"iDisplayLength":10,
"iTotalRecords":2,"iTotalDisplayRecords":2,"data":data_ne}
return jsonify(results)
当我在下方发送此 json 响应时 return
{
"iDisplayStart": 1,
"iDisplayLength": 10,
"iTotalRecords": 2,
"iTotalDisplayRecords": 2,
"data": [
{data_ne}]}
但我想像下面这样在单行中
{"iDisplayStart":1,"iDisplayLength":10,"iTotalRecords":2,"iTotalDisplayRecords":2,"data":data_ne}
有什么办法吗?感谢您的考虑。
你 运行 Flask 处于调试模式吗?尝试将 JSONIFY_PRETTYPRINT_REGULAR
环境变量设置为 false。来自 documentation:
The default output omits indents and spaces after separators. In debug mode or if JSONIFY_PRETTYPRINT_REGULAR is True, the output will be formatted to be easier to read.