在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'
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
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: []
请求解决
@落花无情人葬月: http://stackoverflow.com/questions/17210483/reverse-for-with-arguments-and-keyword-arguments-not-found
@刘宏玺: 是我返回的return render(request,'common/resetpassword.html',locals())这里面的resetpassword.html'页面出错了,并不是其他的原因,感谢你的解答