6

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.

Sreekanth Reddy Balne
  • 3,264
  • 1
  • 18
  • 44
  • 1
    You may want to check out the celery library. It functions as a task manager to help long-running tasks keep from blocking other requests. It's commonly used with django and flask (can't link because of a network issue getting to their homepage) – C.Nivs Aug 10 '18 at 17:03
  • Check out [Django's async support](https://docs.djangoproject.com/en/dev/topics/async/) – Anupam Feb 17 '21 at 14:23
  • [question] https://stackoverflow.com/questions/62390314/how-to-call-asynchronous-function-in-django – Reşat ARIKAN May 08 '22 at 23:45

1 Answers1

3

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

yorodm
  • 4,359
  • 24
  • 32