Python can';t服务于公共静态文件 app=Flask(\uuuuu name\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu, 静态路径=“”, 静态\u url\u路径=无, 静态文件夹=“模板/资产”, template_folder='templates', 实例路径=无, 实例\相对\配置=False) app.debug=False @app.route(“/”,方法=['GET'])) def index(): 返回渲染模板(“index.html”) @app.route('/results/',methods=['GET']) def SERVER_静态(文件名): root\u dir=os.path.dirname(os.getcwd()) #对于windows也是如此 返回app.send\u static\u文件(os.path.join('results',filename.replace('\\\','/'))

Python can';t服务于公共静态文件 app=Flask(\uuuuu name\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu, 静态路径=“”, 静态\u url\u路径=无, 静态文件夹=“模板/资产”, template_folder='templates', 实例路径=无, 实例\相对\配置=False) app.debug=False @app.route(“/”,方法=['GET'])) def index(): 返回渲染模板(“index.html”) @app.route('/results/',methods=['GET']) def SERVER_静态(文件名): root\u dir=os.path.dirname(os.getcwd()) #对于windows也是如此 返回app.send\u static\u文件(os.path.join('results',filename.replace('\\\','/')),python,python-3.x,flask,Python,Python 3.x,Flask,我做错了什么? 这给了我一个错误: 找不到服务器上找不到请求的URL。如果你 手动输入URL请检查拼写并重试 可能值得检查os.path.join('results',filename.).replace('\\\','/')的计算结果 您是否尝试过使用send\u from\u directory的(稍微安全一点的)方法 (没有检查它是否真的有效): @app.route('/results/',methods=['GET']) def SERVER_静态(文件名): 从目录返回发送目录(os

我做错了什么? 这给了我一个错误:

找不到服务器上找不到请求的URL。如果你 手动输入URL请检查拼写并重试


可能值得检查
os.path.join('results',filename.).replace('\\\','/')
的计算结果

您是否尝试过使用
send\u from\u directory
的(稍微安全一点的)方法

(没有检查它是否真的有效):

@app.route('/results/',methods=['GET'])
def SERVER_静态(文件名):
从目录返回发送目录(os.path.dirname(os.getcwd()),文件名)

嗯,如果将
静态文件夹
定义为
模板/资产
而不是
资产
@IgnacioVergaraKausel不起作用,则
静态文件夹
定义为
模板/资产
,你想得到
results.csv
我想你应该得到
http://127.0.0.1:5000/results/result.csv
(假设您在服务器上的
模板/assets
文件夹中有一个
result.csv
文件)
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('\\','/'))
@app.route('/results/<path:filename>', methods=['GET'])
def serve_static(filename):
    return send_from_directory(os.path.dirname(os.getcwd()), filename)