Sha*_*rat 3 forms email django
我创建了以下表格:
class ContactForm(forms.Form):
full_name = forms.CharField(required=False)
email = forms.EmailField()
message = forms.CharField(widget=forms.Textarea(attrs={'class':'special', 'size': '40'}))
Run Code Online (Sandbox Code Playgroud)
但是,当我在“消息”字段中添加一些数据时,它不会出现在与此表单关联的电子邮件中,并具有 Settings.py 中提到的设置。但全名和电子邮件都正常。
我的看法是:
def contact(request):
title = "Contact Us"
form = ContactForm(request.POST or None)
if form.is_valid():
form_email = form.cleaned_data.get('email')
form_message = form.cleaned_data.get('message')
form_full_name = form.cleaned_data.get('full_name')
subject = "Site Contact Form"
from_email = settings.EMAIL_HOST_USER
to_email = [from_email, myemail@gmail.com']
contact_message = "%s: %s via %s"%(form_full_name, form_message, form_email)
html_template = "<h1>Hello There</h1>"
send_mail(subject, contact_message, from_email, to_email, html_message=html_template, fail_silently=True)
context = {
"form":form,
"title": title
}
return render(request, 'contact/form.html', context)
Run Code Online (Sandbox Code Playgroud)
另外,我需要知道创建某种表单以直接将信息接收到我的电子邮件的最佳选择是什么。我应该使用基于模型的表单还是没有模型的简单表单?请告知,因为我的消息字段文本没有出现在电子邮件中,但姓名和电子邮件显示正常。
尝试这个,
message = forms.CharField(widget=forms.TextInput(attrs={'class':'special', 'size': '40'}))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2828 次 |
| 最近记录: |