我的代码是这样的:
success_msg='''\
<html>
Hi. {{ name }}
...
'''
def sendmail(sender,receiver,title,content,username):
...
if __name__ == '__main__':
sendmail(XXX,XXX,XXX,success_msg,usernameXX)
如何在html中将“用户名”传递给“名字”? 如何在html中编写代码?
答案 0 :(得分:1)
>>> from string import Template
>>> msg = Template("Hi $name")
>>> msg.substitute(name='World')
'Hi World'
HTML示例:
>>> header = '<html><head><title>Sample</title></head><body>'
>>> body = '<p>Hello <strong>$name</strong></p>'
>>> footer = '</body></html>'
>>> html = Template(header+body+footer)
>>> html.substitute(name='World')
'<html><head><title>Sample</title></head><body><p>Hello <strong>World</strong></
p></body></html>'