如何使用python将参数传递给html字符串?

2024-09-30 10:41:30 发布

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

我相信这是微不足道的,但我不能把我的参数到我的HTML字符串。我从https://templates.campaignmonitor.com/下载了一个标准模板。我试过:

摘自'索引.html':

< p align="left" class="article-title">< singleline label="Title">%(headline)< /singleline>< /p>

以下是一些代码作为输入:

f = open('index.html','r')
html = str(f.read())
html_complete = html % (headline='Today is the day')

这会导致语法错误。(html打印很好)。你知道吗

我也尝试了{}表示法,但我得到了一个键错误,可能是因为html中到处都是“{”。你知道吗


Tags: 字符串httpscom模板参数标准htmlleft
1条回答
网友
1楼 · 发布于 2024-09-30 10:41:30

在你的队伍里

html_complete = html % (headline='Today is the day')

试试这个:

html_complete = html % dict(headline='Today is the day')

避免语法错误。你知道吗

并根据Jan Hudec在回答中的陈述修复HTML模板(添加s)。你知道吗

注意:dict(a=b){ "a": b }相同,只是有助于避免双引号。你知道吗

相关问题 更多 >

    热门问题