如何在浏览器中打开静态YAML文件而不是下载? (烧瓶)

问题描述 投票:0回答:1

我的 Flask 应用程序带有一个静态文件夹,其中包含

.txt
.json
.yml
文件:

├─ static/
│  ├─ file.txt
│  ├─ file.json
│  └─ file.yml
└─ app.py
# app.py

from flask import Flask

app = Flask(__name__)

if __name__ == '__main__':
    app.run(debug=True)

当我将浏览器指向 http://localhost:5000/static/file.txt 或 http://localhost:5000/static/file.json 时,文件会在浏览器中呈现预览。但是,当我尝试 http://localhost:5000/static/file.yml 时,会下载该文件。

如何在浏览器中打开

.yml
文件,如
.txt
.json
?我发现有一个
Content-Disposition
响应标头控制此行为,但我不确定这如何与
static/
文件夹内的资源一起使用。

python flask yaml
1个回答
0
投票

content-type
标题设置为
text/yaml

© www.soinside.com 2019 - 2024. All rights reserved.