好的,我遇到了一个有效的解决方案。这是我的解决方案。
我改变了 forms.py 喜欢以下
forms.py
from django import forms from accounts.tasks import send_mail from django.contrib.auth.forms import PasswordResetForm as PasswordResetFormCore class PasswordResetForm(PasswordResetFormCore): email = forms.EmailField(max_length=254, widget=forms.TextInput( attrs={ 'class': 'form-control', 'id': 'email', 'placeholder': 'Email' } )) def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name=None): context['user'] = context['user'].id send_mail.delay(subject_template_name=subject_template_name, email_template_name=email_template_name, context=context, from_email=from_email, to_email=to_email, html_email_template_name=html_email_template_name)
而改变了 tasks.py 就像以下一样
tasks.py
from __future__ import absolute_import, unicode_literals from accounts.models import User from django.contrib.auth.forms import PasswordResetForm @shared_task def send_mail(subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name): context['user'] = User.objects.get(pk=context['user']) PasswordResetForm.send_mail( None, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name )