繁体   English   中英

使用 Flask 提供 React 包和 static 文件?

[英]Serve both React bundle and static files with Flask?

我正在使用 Flask/Gunicorn 服务器来为我的 React 构建和 static 文件提供服务。 两者都存储在同一个 /static/ 文件夹中,如下所示:

app = Flask(__name__, static_folder='./static', static_url_path='/')

我可以用下面的代码做任何一个:

  1. 服务 index.html 以进行反应:
@app.route('/')
def index():
    return app.send_static_file('index.html')
  1. 提供音频文件(例如 /static/finished123.mp3)
@app.route('/static/<path:path>')
def send_mp3(path):
    return send_from_directory('static', path)

当我有 2) 处于活动状态时,我无法将 index.html 提供给新客户端,但可以提供 mp3 文件(使用缓存页面测试)。

当我 1) 处于活动状态时,我无法提供 mp3 文件。

我怎样才能两者兼得?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM