Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Python在HTML中插入多行超链接_Python_Html - Fatal编程技术网

通过Python在HTML中插入多行超链接

通过Python在HTML中插入多行超链接,python,html,Python,Html,要在html正文中显示多行,请使用简单代码: websites = ["https://www.reddit.com/","https://en.wikipedia.org/","https://www.facebook.com/"] html = """ <!DOCTYPE html> <html> <body> <h1>Hi, friend</h

要在html正文中显示多行,请使用简单代码:

websites = ["https://www.reddit.com/","https://en.wikipedia.org/","https://www.facebook.com/"]

html = """
<!DOCTYPE html>
<html>
<body>

<h1>Hi, friend</h1>
<p>$websites!</p>

</body>
</html>
"""

html = Template(html).safe_substitute(websites = "<p>".join(websites))
将行更改为:

<p><a href=$websites>$names</a></p>

以及:

html=Template(html).安全替换(websites=“”)。加入(websites),
name=“”。加入(名称))
我想在html中显示的是:

但是它没有正确地显示出来。 正确的方法是什么?谢谢。

不要做
“”。加入(网站)
。这将通过连接列表中的所有元素创建一个字符串,并在它们之间粘贴
“”

因此,这将为您提供
”https://www.reddit.com/https://en.wikipedia.org/“https://www.facebook.com/“
这不是您想要的(我认为它也不正确)

您没有任何

这就是您想要做的:

websites=[”https://www.reddit.com/","https://en.wikipedia.org/","https://www.facebook.com/"]
html=”“”
$websites

""" 标签名称=['News'、'Info'、'Media'] a_links='
'。join([f''表示链接,zip中的链接名称(网站、标签名称)]) html=模板(html).安全替换(网站=链接)
你得到的实际HTML是什么样子的?你知道它应该是什么样子吗?在HTML级别,它到底有什么区别?@KarlKnechtel,谢谢你的评论。上面是我为电子邮件内容创建的实际HTML。编辑时,标题有一行。太棒了!感谢你分享知识,让学习世界变得美丽!超级不客气。你什么都明白了吗?还是有什么需要澄清的。
<p><a href=$websites>$names</a></p>
html = Template(html).safe_substitute(websites = "<p>".join(websites),
                                        names= "<p>".join(names))