2014-12-19 1 views
0

아래의보기를 사용하여 이메일을 보내는 html로 이메일 템플릿을 만들었습니다. 잘 작동합니다. 하지만 이메일을 받으면 RAW HTML 형식으로 표시됩니다. 오류인지 알 수 있습니까? 당신이 장고 1.7을 사용하는 경우 여기에 설명 된대로django의 이메일 템플리트

def confirmed_email_notification(sender, **kwargs): 
    """ 
    Sends an email notification to the shop owner when a new order is 
    completed. 
    """ 
    print "EMAIL NOTIFICATION " 
    subject_template_name = 'shop_simplenotifications/confirmed_subject.txt' 
    body_template_name = 'shop_simplenotifications/confirmed_body.html' 
    request = kwargs.get('request') 
    order = kwargs.get('order') 
    subject = loader.render_to_string(
     subject_template_name, 
     RequestContext(request, {'order': order}) 
    ) 
    subject = subject.join(subject.splitlines()) 
    body = loader.render_to_string(
     body_template_name, 
     RequestContext(request, {'order': order}) 
    ) 
    from_email = getattr(settings, 'SN_FROM_EMAIL', 
         settings.DEFAULT_FROM_EMAIL) 
    owners = getattr(settings, 'SN_OWNERS', settings.ADMINS) 
    send_mail(subject, body, from_email, 
       [owner[1] for owner in owners], fail_silently=False) 
    print body 
    print [owner[1] for owner in owners] 
confirmed.connect(confirmed_email_notification) 

답변

0

, 당신은 그렇지 https://docs.djangoproject.com/en/1.7/topics/email/#send-mail

당신이 EmailMultiAlternatives 클래스를 사용할 수 있습니다 CF의 html_message 인수로 send_mail()에 메시지의 HTML 버전을 전달할 수 있습니다 https://docs.djangoproject.com/en/1.6/topics/email/#sending-alternative-content-types

또는 EmailMessage 클래스를 사용하고 content_subtype 특성을 "html"로 설정하십시오.

그냥 보조 노트 :

>>> subject = "hello Huston\nWe have a\nproblem" 
>>> print subject.join(subject.splitlines()) 
hello Hustonhello Huston 
We have a 
problemWe have ahello Huston 
We have a 
problemproblem 
>>> 
: 정말 당신이 무엇을 기대 할 subject.join(subject.splitlines()) 의심