Python主导包|添加<style>到htm

2024-09-17 07:37:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python中的主导包生成一个html。对于格式,我必须在标记中添加一个简短的CSS内容。但是,我能找到的唯一文档是github页面,该页面没有任何与添加。有人能帮我吗?谢谢您!在

附言:这是一张图片 enter image description here


Tags: 文档标记github内容html格式图片页面
1条回答
网友
1楼 · 发布于 2024-09-17 07:37:10

这就是你要找的吗?from here

import dominate
from dominate.tags import link, script, style

doc = dominate.document(title='Dominate your HTML')

with doc.head:
    link(rel='stylesheet', href='style.css')
    script(type='text/javascript', src='script.js')
    style("""\
         body {
             background-color: #F9F8F1;
             color: #2C232A;
             font-family: sans-serif;
             font-size: 2.6em;
             margin: 3em 1em;
         }

     """)

print(doc.render(pretty=True))

它产生了

^{pr2}$

相关问题 更多 >