搜索结果json
@app.route('/<path>') def info(path): resp = make_response(open(path).read()) resp.headers["Content-type"]="application/json;charset=UTF-8" return resp
按道理应该是能够生效的,但我在用的时候却报错了app
出现错误
IOError: [Errno 2] No such file or directory: u'readme.json'
竟然找不到这个文件code
解决办法
使用绝对路径io
@app.route('/<path>') def today(path): base_dir = os.path.dirname(__file__) resp = make_response(open(os.path.join(base_dir, path)).read()) resp.headers["Content-type"]="application/json;charset=UTF-8" return resp
访问 127.0.0.1:5000/readme.jsonclass