繁体   English   中英

如何在龙卷风中使用静态文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM