我没有使用过瓶子,但是大多数Web框架都要求你将css / js / images放在一个特定的目录中(通过配置设置).通常它被称为“静态”或类似的东西.
我敢打赌,如果你试图直接在浏览器中加载这些CSS文件:
http://localhost:8080/demo.css
你会得到404.
您当前设置的方式就是您为传统的PHP / CGI工作做的事情 – 您的Web服务器正在寻找磁盘上的文件并为它们提供服务.框架(通常)不会那样工作 – 您设置了路由规则.
你用@route(‘/’)装饰器做到了 – 通过设置它,你告诉瓶子“对http:// localhost:8080 /的任何请求应该运行播放器功能并返回它生成的任何内容.”请注意,您尚未为css文件设置任何规则.
另一种可能性是你没有在HTML中正确引用CSS文件.如果您在直接加载CSS文件时没有获得404,请发布HTML,我们可以看一下.
编辑:在瓶子文件中找到这个:
Static files such as images or CSS files are not served automatically. You have to add a route and a callback to control which files get served and where to find them:
from bottle import static_file
@route('/static/')
def server_static(filename):
return static_file(filename, root='/path/to/your/static/files')