Python瓶静态文件不适用CSS

问题描述 投票:0回答:1

所以我正在制作一个python瓶子网站并尝试将CS​​S应用于具有静态文件的页面。但它并不适用,即使它适用于所有其他路线。 html中的链接与所有其他链接相同,在检查中没有错误可见。

@get('/add/<filename:re:.*\.css>')
@get('/view/<filename:re:.*\.css>')
@get('/edit/<filename:re:.*\.css>')
@get('/<filename>')
def staticCSS(filename):
    return static_file(filename, root='views/css/')

这适用于除/edit/<username>/<title>之外的所有路线我不知道是什么原因造成这种情况。

python css bottle static-files
1个回答
1
投票

在我看来,你过度复杂了静态文件方法。我发现最简单的事情就是:

@route('/static/<filepath:path>')
def server_static(filepath):
    return static_file(filepath, root='/static')

这使得static文件夹中的所有内容都可以通过直接链接访问。这更容易管理,因为您可以在所需的静态下使用任何类型的嵌套子文件夹结构。

© www.soinside.com 2019 - 2024. All rights reserved.