web2py 链接到 CSS
我正在学习 web2py 1.98.2,所以这个问题非常基本。在 static/css 文件夹中,我创建了包含以下内容的 basic.css 文件:
.auth_navbar {
top: 0px;
float: right;
padding: 3px 10px 3px 10px;
}
在 layout.html 中,我有:
<head>
...
{{response.files.append(URL('static','css/base.css'))}}
...
</head>
<body>
...
{{try:}}{{=auth.navbar(action=URL('default','user'))}}{{except:pass}}
...
</body>
控制器 default.py 有非常简单的代码:
def index(): return dict(message="hello people")
最后,default/index.html 看起来像:
{{extend 'layout.html'}}
<h2>This is the default/index.html template</h2>
{{#=BEAUTIFY(response._vars)}}
所以,我运行应用程序并且index.html 按预期显示。但是,CSS 不起作用。 我期望页面源代码中有以下行:
<link href="/welcome/static/css/base.css" rel="stylesheet" type="text/css" />
但它不存在。我缺少什么?
I'm learning web2py 1.98.2, so the question is very basic. In static/css folder I created basic.css file with the following content:
.auth_navbar {
top: 0px;
float: right;
padding: 3px 10px 3px 10px;
}
In layout.html I have:
<head>
...
{{response.files.append(URL('static','css/base.css'))}}
...
</head>
<body>
...
{{try:}}{{=auth.navbar(action=URL('default','user'))}}{{except:pass}}
...
</body>
Controller default.py has very simple code:
def index(): return dict(message="hello people")
And, lastly, default/index.html looks like:
{{extend 'layout.html'}}
<h2>This is the default/index.html template</h2>
{{#=BEAUTIFY(response._vars)}}
So, I run the app and index.html is displayed as expected. However, CSS is not working.
I expected the following line in the page source:
<link href="/welcome/static/css/base.css" rel="stylesheet" type="text/css" />
but it's not there. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的行只是将base.css 添加到response.files 列表中。
标记由 web2py_ajax.html 模板生成,该模板包含在默认的layout.html 中。因此,您需要确保 web2py_ajax.html 也包含在您的layout.html中,并且base.css添加到response.files之前。所以:
请注意,您的第一句话指的是 basic.css,但您的代码指的是 base.css - 确保您使用正确的文件名(web2py 带有自己的 base.css)。
The above line simply adds base.css to the response.files list. The
<link>
tag is generated by the web2py_ajax.html template, which is included in the default layout.html. So, you need to make sure that web2py_ajax.html is also included in your layout.html, and that base.css is added to response.files before that. So:Note, your first sentence refers to basic.css, but your code refers to base.css -- make sure you're using the right filename (web2py comes with its own base.css).
您可能遗漏了:
在layout.html 的正文标记中。
It's possible that you left out:
In the body tags of your layout.html.