使用Django模板化电子邮件的错误

时间:2013-03-31 04:11:49

标签: django django-email

我正在尝试使用Django-Templated-Email(0.4.7)发送电子邮件,并且我一直收到以下错误:

TypeError at /intake/basic/
send_templated_mail() takes at least 4 arguments (4 given)
Request Method: POST
Request URL:    http://127.0.0.1:8000/intake/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:    
send_templated_mail() takes at least 4 arguments (4 given)

以下是来自views.py:

的代码摘录
from templated_email import send_templated_mail

class IntakeFormView(CreateView):
"""
Creates intake form request
"""
model = Intake
form_class = IntakeForm
template_name = 'intake.html'
success_url = '/intake/sent/'

def form_valid(self, form):
    # Save form to database
    self.object = form.save()

    from_email = 'from@fakemail.com'
    recipient_list = ['get@fakemail.com']

    send_templated_mail(context=
        {'client': self.object.client, 
         'type': self.object.type,     
         'issue': self.object.issue},
    template_name='intake',
    to=['to@fakemail.com'],
    bcc=recipient_list,
    from_email=from_email)

    return HttpResponseRedirect(self.get_success_url())

以下是intake.email模板文件:

{% block subject %}
CLIENT ALERT: {{type}}
{% endblock %}

{% block plain %}

{{client}} needs help re {{issue}}.

{% endblock %}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

send_templated_email没有to作为关键字参数。您需要使用recipient_list

send_templated_email(
    recipient_list = ['to@fakemail.com']
    # your other arguments
)