0
我有這個網站,用戶可以填寫表格,當他們打開時提交表格的所有結果通過電子郵件發送給我。表格的所有部分都會從下拉菜單中發送,除非他們選擇了。有人知道我的代碼出錯了嗎? 這裏是我的forms.py如何將選定的下拉菜單的值發送到django的電子郵件地址
CONDOS=[
('silvermountaincondo', 'Silver Mountain Condo'),
('redhillcondo', 'Red Hill Condo'),
('lakesidecondo', 'Lakeside Condo'),
('pointeplacecondo', 'Pointe PLace Condo'),
('rhodesviewcondo', 'Rhodes View Condo'),
]
class ContactForm(forms.Form):
contact_name = forms.CharField(required=True, label='Full name')
contact_email = forms.EmailField(required=True, label='Email Address')
contact_phone = forms.CharField(required=True, label='Phone number')
condo = forms.ChoiceField(required=True, label='Which condo would you like to reserve?', choices=CONDOS)
arrival_date = forms.DateField(required=True, help_text='Please enter your arrival date (YYYY-MM-DD)')
departure_date = forms.DateField(required=True, help_text='Please choose your departure date (YYYY-MM-DD)')
這裏是我的views.py
def contact(request):
form_class = ContactForm
if request.method =='POST':
form = form_class(data=request.POST)
if form.is_valid():
contact_name = request.POST.get('contact_name', '')
contact_email = request.POST.get('contact_email','')
contact_phone = request.POST.get('contact_phone','')
condo = request.POST.getlist('condo','')
arrival_date = request.POST.get('arrival_date','')
departure_date = request.POST.get('departure_date','')
template = get_template('contact_template.txt')
content = template.render({
'contact_name': contact_name,
'contact_email': contact_email,
'contact_phone': contact_phone,
'condo': condo,
'arrival_date': arrival_date,
'departure_date': departure_date,
})
send_mail(
"New Booking from vacationcondos.vegas",
content,
"www.vacationcondos.vegas" + '',
['[email protected]'],
#headers = {'Reply-To': contact_email}
)
return redirect('Properties/contact')
return render(request, 'Properties/contact.html', {
'form': form_class,
})
這是一個什麼樣的郵件看起來像
聯繫人名稱的例子:約翰史密斯
電子郵件:[email protected]
聯繫電話號碼:5555555555
到貨日期:2017年7月30日
出發日期:2017年8月13日
在應該打印從下拉列表中選擇的公寓的電話號碼和到達日期間。
謝謝你解決了我的問題。 – Tedgar