sending email templates in with django
I want to send an email with a template like this.
{% extends "base.html" %}
{% block content %}
<h2>Invoice Details</h2>
<div id="horizontalnav">
<a href="/index/add_invoice">Add an Invoice</a>
<a href="/index/work_orders">Add a Work Order</a>
<a href="/index/add_payment">Add Payment</a>
</div>
<ul STYLE="border: 1px solid;float:left;padding:15px; width: 700px;">
<h2 STYLE="text-align: right; COLOR:blue; Font-family:ARIAL">
INVOICE</h2>
<br/>
<b>company</b>
<br/>
<div id="list">
{% for invoice in invoices_list %}
<p style="text-align: right;">INVOICE # {{invoice.invoice_no}}<br/>
{{invoice.date}}<br/>
{{invoice.contract_info}}<br/>
{% for invoice in invoice.work_orders.all %}
{{invoice}}<br/>
{% endfor %}
{% endfor %}
<p style="text-align: left">
<p>To</p>
{{client.company}}<br/>
{{client.address}}<br/>
{{client.city}}<br/>
{{client.postcode}}<br/>
<p>
</div>
</ul>
{% endblock %}
I want to send fully html powered templates, with django datas. However I am having some problems. I am getting this error.
"to" argument must be a list or tuple
I am assuming there might be a problem with my views with the send to email domain, but there should not be a problem with this. I somehow am getting stuck with this.
#views.py
@login_required
def invoice_mail(request):
t = loader.get_template('registration/email.txt')
c = Context({
'invoices_list': 'invoices_list',
'clients_list': 'clients_list',
})
send_mail('Welcome to My Project', t.render(c), 'joe@example.com', '[tom@example.com]', fail_s开发者_开发技巧ilently=False)
send_mail('Welcome to My Project', t.render(c), 'joe@example.com', '[tom@example.com]', fail_silently=False)
has to be
send_mail('Welcome to My Project', t.render(c), 'joe@example.com', ['tom@example.com'], fail_silently=False)
The error message is fairly explicit. The to
argument to send_mail
, which is the fourth positional argument, needs to be a list or tuple. You're passing a string, with brackets inside the string, for some reason.
send_mail('Welcome to My Project', t.render(c), 'joe@example.com',
['tom@example.com'], fail_silently=False)
'[tom@example.com]'
is not a list, it is a string with square brackets at each end. Try ['tom@example.com']
instead.
精彩评论