Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
邮件功能不支持';不要用Django发邮件_Django - Fatal编程技术网

邮件功能不支持';不要用Django发邮件

邮件功能不支持';不要用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<

我用基本的HTML标记编写代码,就像这样,没有问题。邮件发送正确。但当我改变它的位置和HTML标签邮件功能不起作用。会有什么问题

它起作用了

<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()