简体   繁体   English

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

[英]How to use static file in Tornado

How do you use static path in Tornado? 在龙卷风中如何使用静态路径?

I've tried the following configuration: 我尝试了以下配置:

settings = {
    'static_path' : 'static'
}

But it's not working. 但这不起作用。

For example, I have this line in my HTML: 例如,我的HTML中包含以下行:

<link href="/static/bootstrap.css" rel="stylesheet">

When I open this URL: http://localhost/static/bootstrap.css 当我打开此URL时: http://localhost/static/bootstrap.css

I'm see an error: 404 Not Found 我看到错误: 404 Not Found

Can anyone explain how to configure static paths in Tornado? 谁能解释如何在Tornado中配置静态路径?

You'll need to change your settings dict to the following, assuming you're running the file from the same location as the static folder: 假设您要从与静态文件夹相同的位置运行文件,则需要将设置字典更改为以下内容:

settings = dict(
        static_path=os.path.join(os.path.dirname(__file__), "static")
    )

Then in your html template you need to use static_url : 然后在您的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