在flask中直接返回list或者dict时出现’dict’ object is not callable的错误
@user_bp.route('/help',methods=['GET'])
def show_user_help():
help_path= "help.pdf"
print('help_path:',help_path)
return dict(download_help_path=help_path)
因为flask不能将list或者dict默认转换成json格式。
方法一:
引入flask_json中的as_json可以解决,如下:
from flask_json import as_json
@user_bp.route('/help',methods=['GET'])
@as_json
def show_user_help():
help_path= "help.pdf"
print('help_path:',help_path)
return dict(download_help_path=help_path)