我是“旋风”的新手。我正在尝试将CSS文件链接到html模板。我用的是jinja2和龙卷风。但是由于一些未知的原因,CSS文件没有加载。
编辑:我已经创建了我的自定义render_template函数,它运行良好。
目录结构:
app.py
static
css
custom.css
templates
index.html这是我的类:
class Index(RequestHandler):
def get(self):
path = os.path.join('static/css/', 'custom.css')
return self.write(render_template('index.html', path = path))下面是我的index.html模板:
<!Doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{path}}"/>
</head>
<body>
<div>
<div class="header">
asdasdasd
</div>
</div><!--wrapper-->
</body>
</html>但是浏览器用正确的url返回css文件的404-NotFound错误,即http://localhost/static/css/custom.css。
发布于 2015-08-05 13:06:10
下面是关于如何链接龙卷风中的静态文件的指南:http://tornado.readthedocs.org/en/latest/guide/running.html#static-files-and-aggressive-file-caching
重要的是设置字典中的“static_path”设置:
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static")
}现在你应该可以使用它了。
https://stackoverflow.com/questions/31830865
复制相似问题