app = Flask(__name__,
static_path='',
static_url_path=None,
static_folder='templates/assets',
template_folder='templates',
instance_path=None,
instance_relative_config=False)
app.debug = False
@app.route("/", methods=['GET'])
def index():
return render_template("index.html")
@app.route('/results/<path:filename>', methods=['GET'])
def serve_static(filename):
root_dir = os.path.dirname(os.getcwd())
#for windows too
return app.send_static_file(os.path.join('results', filename).replace('\\','/'))
我做错了什么? http://127.0.0.1:5000/assets/result.csv 这给了我一个错误:
未找到在服务器上找不到请求的URL。如果你 手动输入网址,请检查拼写,然后重试。
答案 0 :(得分:1)
可能值得检查os.path.join('results', filename).replace('\\','/')
评估的内容。
您是否尝试使用send_from_directory
(更安全)的方法?
(未检查它是否确实有效):
@app.route('/results/<path:filename>', methods=['GET'])
def serve_static(filename):
return send_from_directory(os.path.dirname(os.getcwd()), filename)