Ajax调用Django发送电子邮件没有响应

时间:2014-05-26 09:37:04

标签: python ajax django

我使用Djrill从我的Django应用程序发送电子邮件。

使用ajax,我按如下方式调用处理电子邮件发送的视图:

$.ajax({
        url: "/sendmail&name="+name+"&receiver="+email+"&phone="+phone+"&address="+address,
        type: 'GET',
        success: function(){
            console.log('done');
        }
    });

views.py就是:

def sendEmail(request):
    if 'receiver' in request.GET and request.GET['receiver']:
        name = request.GET['name']
        recv = request.GET['receiver']
        phone = request.GET['phone']
        address = request.GET['address']
        from django.core.mail import send_mail
        send_mail("Service name: "+name, "Phone Number: "+phone+" <br>Address: "+address, "<sender@example.com", [recv])
        return 'True Data'
    else:
        return 'False data'

Urls.py

url(r'^sendmail$', views.sendEmail, name='sendmail'),

对ajax调用的响应给出了404错误。

知道这里发生了什么吗?

1 个答案:

答案 0 :(得分:4)

请求中的网址应为sendmail?而不是sendmail&

url: "/sendmail?name="+name+"&receiver="+email+"&phone="+phone+"&address="+address,
               ^ there

否则,它正在寻找一个格式为sendmail&name=(.+)的网址,显然不存在。

有关详细信息,请参阅Query string structure(但我认为这也是您的错字)