Knio / dominate

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.
GNU Lesser General Public License v3.0
1.71k stars 110 forks source link

the title is wrong标题乱码 #180

Closed ianutin closed 1 year ago

ianutin commented 1 year ago

我使用以下代码生成一个头部导航: from dominate.tags import * import dominate

' html_head

def setHtmlHeader(obj,html_title):

' 添加 等头部信息

with obj.head:
    meta(charset="UTF-8")
    meta(name="viewport",content="width=device-width, initial-scale=1.0")
    title(html_title)
    link(rel="stylesheet",href="src/css/templatemo_main.css")
print("ok")

def setTitle(obj):

' 渲染标题栏

title_1=img(cls="logo4",src="src/pics/button.png")
#title_1=h1("单细胞转录组测序分析报告")
title_2=a(href="#1")
title_3_1=div(style="float: left;",cls="aa")
title_2.add(title_1)
title_3_1.add(title_2)
title_3_2=h1("单细胞转录组测序分析报告")
title_4=div(cls="logo",style="width: 100%;")
title_4.add(title_3_1)
title_4.add(title_3_2)
title_5=div(cls="navbar-header",style="position:fixed;")
title_5.add(title_4)
title_6=div(cls="navbar navbar-inverse",role="navigation")
title_6.add(title_5)
obj.add(title_6)

def main(): html_title = "单细胞转录组测序分析报告" html_root=dominate.document(lang="en",doctype="<!DOCTYPE html>") setHtmlHeader(html_root,html_title) setTitle(html_root) with open('E:/2023洛兮医疗/01.资料/05.html_test/03.reports_out/03.reports_out/test.html','w') as f: f.write(html_root.render()) 但是得到的网页却是乱码! image 不知道是哪里出了问题...

ianutin commented 1 year ago

image

ianutin commented 1 year ago

可是把相同的html内容复制到test2.html中,打开又不是乱码

ianutin commented 1 year ago

解决了,纯纯是中文编码的问题