web2py 链接到 CSS

发布于 2024-12-01 07:37:47 字数 930 浏览 1 评论 0原文

我正在学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

み格子的夏天 2024-12-08 07:37:47
{{response.files.append(URL('static','css/base.css'))}}

上面的行只是将base.css 添加到response.files 列表中。 标记由 web2py_ajax.html 模板生成,该模板包含在默认的layout.html 中。因此,您需要确保 web2py_ajax.html 也包含在您的layout.html中,并且base.css添加到response.files之前。所以:

{{response.files.append(URL('static','css/base.css'))}}
{{include 'web2py_ajax.html'}}

请注意,您的第一句话指的是 basic.css,但您的代码指的是 base.css - 确保您使用正确的文件名(web2py 带有自己的 base.css)。

{{response.files.append(URL('static','css/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:

{{response.files.append(URL('static','css/base.css'))}}
{{include 'web2py_ajax.html'}}

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).

楠木可依 2024-12-08 07:37:47

您可能遗漏了:

{{include}}

在layout.html 的正文标记中。

It's possible that you left out:

{{include}}

In the body tags of your layout.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文