邮件功能不支持';不要用Django发邮件
我用基本的HTML标记编写代码,就像这样,没有问题。邮件发送正确。但当我改变它的位置和HTML标签邮件功能不起作用。会有什么问题 它起作用了邮件功能不支持';不要用Django发邮件,django,Django,我用基本的HTML标记编写代码,就像这样,没有问题。邮件发送正确。但当我改变它的位置和HTML标签邮件功能不起作用。会有什么问题 它起作用了 <h1>Contact Us</h1> <form method="post"> {% csrf_token %} {{ form.as_p }} <div class="form-actions"> <button type="submit">Send<
<h1>Contact Us</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<div class="form-actions">
<button type="submit">Send</button>
</div>
</form>
如您所述的表格
不起作用
:
<form class="contact-form" action="" method="GET">
{% csrf_token %}
{% for field in form %}
{{ field|add_class:"input" }}
{% endfor %}
<button class="button" type="submit">Send</button>
</form>
在这里,您使用了POST方法块中发送邮件的代码,如下所示:
else:
form = ContactForm(request.POST or None)
if form.is_valid():
fullname = form.cleaned_data['fullname']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(fullname, message, from_email,
['gulnarnecefova1996@gmail.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('home')
因此,当您提交表单时,它将作为get
请求发送。此块正在处理get
请求:
if request.method == 'GET':
form = ContactForm()
因此,邮件功能不起作用
尝试将方法更改为html表单中的post
。您得到的错误是什么?还包括您的view@Sanip不幸的是,我没有得到任何错误。当我按下提交按钮时,我看到eWebryThing是用GET方法发送的。但我在中使用了POST方法form@Gasanov我包括在您的非工作表中,您已将方法指定为post
非常感谢。还有一个问题。“post”和“post”之间有什么区别吗。我的意思是,首字母有什么影响吗?在html表单方法属性中,您可以同时使用这两种方法。
def index(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST or None)
if form.is_valid():
fullname = form.cleaned_data['fullname']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(fullname, message, from_email,
['gulnarnecefova1996@gmail.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('home')
context['form'] = form
return render(request, "index.html", context)
else:
form = ContactForm(request.POST or None)
if form.is_valid():
fullname = form.cleaned_data['fullname']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(fullname, message, from_email,
['gulnarnecefova1996@gmail.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('home')
if request.method == 'GET':
form = ContactForm()