我的 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/
文件夹内的资源一起使用。
将
content-type
标题设置为 text/yaml
。