gpt4 book ai didi

python-3.x - 如何在 django 2 的 html 内容中传递值

转载 作者:行者123 更新时间:2023-12-03 11:18:16 25 4
gpt4 key购买 nike

我试图创建一个约会系统,其中约会系统将向用户发送邮件,邮件数据将是动态的,但问题是我如何在 html_content 中传递数据,就像日期是一个变量一样,我如何在其中传递日期值 session 日期 + 符号不起作用,因为我的字符串不是 HTML 代码

这是我的代码

subject, from_email, to = 'You Have A Meeting Request', 'send@gmail.com', 'text@gmail.com'
text_content = 'Dear Sir,'
date = 12-12-2018
html_content = '<p>This is an ' \
'<strong>Meeting Request</strong>' \
' <ul>' \
'<li><b>Meeting Date:</b> {{ date }}</li>' \
'<li><strong>Meeting Place:</strong> DRL , Meeting Room 1</li>' \
'<li><strong>Time:</strong> 10-30 To 13-30</li>' \
'<li><strong>Meeting Purpose:</strong> For Opening Appointment</li>' \
'<li><strong>No Of Person:</strong> 5</li>' \
'<li><strong>Priority:</strong> High</li>' \
'<li><strong>Request By:</strong> Mr X</li>' \
'</ul>.</p>'

msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()

最佳答案

为什么不做这样的事情:

html_content = '''
<p>This is an
<strong>Meeting Request</strong>
<ul>
<li><b>Meeting Date:</b> %s</li>
<li><strong>Meeting Place:</strong> DRL , Meeting Room 1</li>
<li><strong>Time:</strong> 10-30 To 13-30</li>
<li><strong>Meeting Purpose:</strong> For Opening Appointment</li>
<li><strong>No Of Person:</strong> 5</li>
<li><strong>Priority:</strong> High</li>
<li><strong>Request By:</strong> Mr X</li>
</ul>.</p>
''' % (date)

关于python-3.x - 如何在 django 2 的 html 内容中传递值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53058553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com