2017-03-06 199 views
0

我試圖發送電子郵件錯誤發送消息

html = get_html_mail(self.request, order) 

email = EmailMultiAlternatives('Subject', 
         html, 
         '[email protected]', 
         # to=[order.shop.email]) 
         to=['[email protected]']) 
email.attach_alternative(html, "text/html") 
email.send() 

但有錯誤,當我嘗試發送電子郵件:

AttributeError at /success/ 

'HttpResponse' object has no attribute 'splitlines' 

我怎樣才能解決這個問題?

def get_html_mail(req, order): 
    request = req 

    return render(request, 'send_mail/send_message.html', {'order': order}) 

HTML

<!DOCTYPE html> 
<html lang="ru"> 
<head> 
<title>Форма заказа</title> 
<meta charset="utf-8"> 
          </tr> 
        </table> 
       </td> 
      </tr> 
     </table> 
    </td> 
    <td class="padd" style="width:15px;" ></td> 
</tr> 
<tr> 
    <td class="padd" style="width:15px;" ></td> 
    <td></td> 
    <td class="padd" style="width:15px;" ></td> 

這是我的消息HTML。它是渲染,並應發送郵件地址

+0

你能顯示出與實際錯誤的行嗎? – nico

回答

1

您正在使用splitlines某處HttpResponseHttpResponse沒有方法splitlines。該錯誤不是由您添加到您的問題的代碼段生成的。

Source of the django's HttpResponse object

找到您正試圖讓你的HttpResponse使用splitlines方法。首先刪除不存在splitlines在您的HttpResponse

+0

我在我的問題中添加新數據請參閱 –

+0

分享您的代碼'成功'方法。這個新添加的代碼也包含這個問題。提交或發送後,您將被重定向到'success'方法,或者正在調用此方法。我不知道綁定到'/ success /'url的方法,通過錯誤通知。該方法包含帶有錯誤的「HttpResponse」。 – Nrzonline

+0

email.send()我有錯誤 –

1

剛剛成立renderrender_to_string TY所有的時間