首页 新闻 会员 周边 捐助

django 发送邮件出错

0
悬赏园豆:60 [已解决问题] 解决于 2016-03-01 11:27

在view当中:

def send_mail(request):
    try:
        subject = 'hello'
        html_content = u'<b>激活链接:</b><a href="http://www.baidu.com">http:www.baidu.com</a>'
        msg = EmailMessage(subject,html_content,EMAIL_HOST_USER,['qq1183534511@sina.com',])
        msg.content_subtype = 'html'
        msg.send()
        return(request,'common/resetpassword.html',locals())
    except Exception as e:
        logger.error(e)
    return render(request,'common/error.html',{'error':e})

在settings当中

#邮件配置
EMAIL_HOST = 'smtp.sina.com'
EMAIL_PORT = '25'
EMAIL_HOST_USER = aaa@sina.com'
EMAIL_HOST_PASSWORD = aaa'
EMAIL_USE_TLS = True

结果报了这样一个错误

AttributeError at /users/send_maiil/

'tuple' object has no attribute 'get'
意发并行的主页 意发并行 | 初学一级 | 园豆:3
提问于:2016-02-29 23:22
< >
分享
最佳答案
0
def send_mail(request):
    try:
        subject = 'hello'
        html_content = u'<b>激活链接:</b><a href="http://www.baidu.com">http:www.baidu.com</a>'
        msg = EmailMessage(subject,html_content,EMAIL_HOST_USER,['qq1183534511@sina.com',])
        msg.content_subtype = 'html'
        msg.send()
        return render(request,'common/resetpassword.html',locals())
    except Exception as e:
        logger.error(e)
    return render(request,'common/error.html',{'error':e})

你看看是不是因为第一个return 后面没写render

收获园豆:60
刘宏玺 | 专家六级 |园豆:14020 | 2016-03-01 10:58
def send_mail(request):
    try:
        subject = 'hello'
        html_content = u'<b>激活链接:</b><a href="http://www.baidu.com">http:www.baidu.com</a>'
        msg = EmailMessage(subject,html_content,EMAIL_HOST_USER,['qq1183534511@sina.com',])
        msg.content_subtype = 'html'
        msg.send()
        return render(request,'common/resetpassword.html',locals())
    except Exception as e:
        logger.error(e)
        return render(request,'common/error.html',{'error':e})
    return render(request,'common/error.html',{'error':'aaa'})

我修改过来了,不过报了一个新的错误

error Reverse for 'updatepassword' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

请求解决

意发并行 | 园豆:3 (初学一级) | 2016-03-01 11:08

@落花无情人葬月: http://stackoverflow.com/questions/17210483/reverse-for-with-arguments-and-keyword-arguments-not-found

刘宏玺 | 园豆:14020 (专家六级) | 2016-03-01 11:15

@刘宏玺: 是我返回的return render(request,'common/resetpassword.html',locals())这里面的resetpassword.html'页面出错了,并不是其他的原因,感谢你的解答

意发并行 | 园豆:3 (初学一级) | 2016-03-01 11:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册