在 settings.py
中设置Debug = Flase之后,在我的网站[www.softdlr.com]中看到服务器错误500。当我用其他语言(英语除外)搜索时会出现此问题
当我使用联系表格
如何解决此错误(我的工作重点是修复我使用gmail的联系表)
forms.py
# contact form
class ContactForm(forms.Form):
contact_name = forms.CharField(required=True,label='Your name ')
contact_email = forms.EmailField(required=True,label='Your email ')
title = forms.CharField(required=True,label='The Subject')
content = forms.CharField(required=True,label='Full Deatils
',max_length=500,widget=forms.Textarea(attrs={"rows":5, "cols":30}) )
views.py
from django.core.mail import send_mail
from first_app import forms
from django.shortcuts import render
from .forms import ContactForm
from django.core.mail import EmailMessage
# Contact form view
def contact(request):
Contact_Form = ContactForm
if request.method == 'POST':
form = Contact_Form(data=request.POST)
if form.is_valid():
contact_name = request.POST.get('contact_name')
contact_email = request.POST.get('contact_email')
contact_content = request.POST.get('content')
title = request.POST.get('title')
template = loader.get_template('html_file/contact_form.txt')
context = {
'contact_name' : contact_name,
'contact_email' : contact_email,
'title' : title,
'contact_content' : contact_content,
}
content = template.render(context)
email = EmailMessage(
"New contact form email",
content,
"Creative web" + '',
['myemail@gmail.com'],
headers = { 'Reply To': contact_email }
)
email.send()
return redirect('Success')
return render(request, 'html_file/contact_us.html', {'form':Contact_Form })
settings.py
# email message contact
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST= 'smtp.gmail.com'
EMAIL_HOST_USER= 'myemail@gmail.com'
EMAIL_HOST_PASSWORD= 'mypass'
EMAIL_USE_TLS= True
EMAIL_PORT= 587
答案 0 :(得分:0)
对于联系表格,我可以通过以下方法解决问题:
转到https://accounts.google.com/DisplayUnlockCaptcha 然后重试手术,请客