[英]How to use static file in 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") }}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.