如何在 Tornado 中使用静态路径?
我尝试了以下配置:
settings = {
'static_path' : 'static'
}
但是它不起作用。
例如,我的 HTML 中有这一行:
<link href="/static/bootstrap.css" rel="stylesheet">
当我打开此 URL 时:http://localhost/static/bootstrap.css
我看到一个错误:404 Not Found
谁能解释一下如何在 Tornado 中配置静态路径?
最佳答案
假设您从与静态文件夹相同的位置运行该文件,您需要将设置字典更改为以下内容:
settings = dict(
static_path=os.path.join(os.path.dirname(__file__), "static")
)
然后在你的html模板中你需要使用static_url
:
<link rel="stylesheet" href="{{ static_url("bootstrap.css") }}" />
关于python - 如何在Tornado中使用静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24661925/