У меня есть приложение в моем проекте Django, который отправляет электронную почту асинхронно во время работы сервера, если температура больше максимальной. Фактически, в начале, я отправляю только одному получателю, и я сравниваю температуру, полученную от функции foo, до постоянной.ТипError: send_mail() принимает ровно 3 аргумента (1 задано)
Но не отправлять сообщения электронной почты ни асинхронно, ни когда я доступ к этому приложению URL возвращает ошибку, говоря:
TypeError: send_mail() takes exactly 3 arguments (1 given)
почты/views.py
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from threading import Thread
from cap import foo
class EmailThread(Thread):
def __init__(self, subject, content, from_email):
self.subject = request.POST.get('subject', 'subject')
self.content = request.POST.get('content', 'attention ! la temperature a depasse le maximum ')
self.from_email = request.POST.get('from_email', '*****@gmail.com')
Thread.__init__(self)
def run(self):
if subject and content and from_email:
try:
send_mail(subject, content, from_email, [ '******@gmail.com' ])
return HttpResponse('templates/mail.html')
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('mail')
else:
return HttpResponse('Make sure all fields are entered and valid.')
def send_mail(subject, content, recipient):
x = foo()
if x >= 12 :
EmailThread(subject, content, recipient).start()
Вы переопределяете 'send_mail' и, возможно, разбиваете его где-то еще, так как вы импортируете его из' django.core.mail' и определяете его самостоятельно –