我的代码是这样的:
success_msg='''\
<html>
Hi. {{ name }}
...
'''
def sendmail(sender,receiver,title,content,username):
...
if __name__ == '__main__':
sendmail(XXX,XXX,XXX,success_msg,usernameXX)
如何在html中将“用户名”传递给“名称”?如何在html中编写代码?
我的代码是这样的:
success_msg='''\
<html>
Hi. {{ name }}
...
'''
def sendmail(sender,receiver,title,content,username):
...
if __name__ == '__main__':
sendmail(XXX,XXX,XXX,success_msg,usernameXX)
如何在html中将“用户名”传递给“名称”?如何在html中编写代码?
使用字符串模板:
>>> 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>'