weasyprint 不在输出文件中应用 css 样式

Ous*_* He 3 python weasyprint

我正在尝试使用带有库的脚本pdf从页面输出。我得到了文件形式的输出,但页面没有样式,但我使用的是 bootstrap css 样式。这是我的代码片段:htmlpythonweasyprintpdfpdf

HTML('./result.html').write_pdf('./result.pdf', stylesheets=[CSS(filename='./bootstrap.css')])
Run Code Online (Sandbox Code Playgroud)

结果.html 文件:

<html>
<head>
    <link rel="stylesheet" href="bootstrap.css">
</head>
<body>
<h1 class='text-primary'>Title</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

WeasyPrint 版本:0.40

fsa*_*sch 5

假设你的路由是正确的,你必须删除 CSS 中的“filename=”,如下所示:

html = HTML('./result.html') #html file location
html.write_pdf(target='./result.pdf', stylesheets=[CSS('bootstrap.css')])
Run Code Online (Sandbox Code Playgroud)