if form.is_valid():
name = form.cleaned_data['name']
phone = form.cleaned_data['phone']
email = form.cleaned_data['email']
content = form.cleaned_data['content']
subject = 'Subject'
body = 'Your data: name: name, phone: phone, your question: content'
如何从表单(姓名,电话和内容)添加电子邮件内容我的数据?
答案 0 :(得分:0)
body = "Your data: name: %s, phone: %s, your question: %s" % (name, phone, content)
或
body = "Your data: name: " + name + ", phone: " + str(phone) + ", your question: " + content
答案 1 :(得分:0)
你可以使用
"Your String".format()
它适用于新旧python版本
答案 2 :(得分:0)
最pythonic方式是使用string.format()
像这样:
first_name = 'Peter'
last_name = 'Pan'
email = 'peter.pan@wunderland.com'
body = 'Hello, my name is {first_name} {last_name}. Send me a mail to {email}.'.format(first_name=first_name, last_name=last_name, email=email)
您还可以在dict
中传递string.format()
。