问题
I am using django 2.0 and python 3.6.
The user registration includes sending of a verification mail. And this mail sending process is taking longer and the user is kept waiting.
What I need?: If the user registration form is valid, mailing details are sent to another task handler and regardless of whether the mail is sent or not, the function must resume and return a response.
def new_user_registration(request):
form = CustomUserCreationForm(request.POST or None)
if form.is_valid():
user = form.save()
send_verification_mail(user) #<= taking more time.
return render(request, 'registration/signup.html')
i.e, the send_verification_mail
must be called asynchronously. How to achieve it?
Note: I am new to django and python.
回答1:
Most of the time you will use a task queue for this.
Celery has been around for a long time and it is well known and documented, but recently I'm moving all my stuff to TaskTiger
来源:https://stackoverflow.com/questions/51790935/django-how-to-execute-a-function-asynchronously-i-e-handover-a-task-to-a-sub-pr