Reputation: 8026
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?
Upvotes: 1
Views: 5285
Reputation: 1705
It's possible that you left out:
{{include}}
In the body tags of your layout.html.
Upvotes: 1
Reputation: 25536
{{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).
Upvotes: 3