gpt4 book ai didi

python - 在 heroku 上使用 flask 提供静态 html 页面

转载 作者:行者123 更新时间:2023-11-28 19:26:02 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 Flask 应用程序从 heroku 提供静态页面。我通过一些搜索找到了这个:

@app.route('/foo/<path:filename>')
def send_foo(filename):
return send_from_directory('/path/to/static/files', filename)

但是,这会非常低效。有没有办法让前置服务器直接为这些文件提供服务?

最佳答案

通常您会使用 mod_rewrite 和 apache 或类似工具来执行此操作,但 afaik heroku 不允许您更改 http 服务器配置。

您需要使用 rack 中间件,它可以让您使用 ruby​​ 编写 url 重写规则。 (检查一下:http://icelab.com.au/articles/useful-heroku-friendly-rewrites-with-rack-rewrite/)

关于python - 在 heroku 上使用 flask 提供静态 html 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12655490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com