Есть ли способ отправить электронное письмо сразу после «обратного перенаправления»?
просмотры.py
Вариант 1: Размещение «send_mail» перед «redirect»
if request.method == 'POST':
formset = TestFormSet(request.POST,request.FILES,instance=project)
if formset.is_valid():
subject = 'Notifications'
html_message = "Testing notifications"
recipient = ["[email protected]"]
send_mail(subject, html_message, EMAIL_HOST_USER, [recipient],fail_silently = False)
formset.save()
return redirect("home")
With Option 1, the email is sent successfully but on the front-end the page has to wait until the email is sent before the redirection takes place.
Вариант 2: Размещение «send_mail» после перенаправления
if request.method == 'POST':
formset = TestFormSet(request.POST,request.FILES,instance=project)
if formset.is_valid():
formset.save()
return redirect("home")
subject = 'Notifications'
html_message = "Testing notifications"
recipient = ["[email protected]"]
send_mail(subject, html_message, EMAIL_HOST_USER, [recipient],fail_silently = False)
При варианте 2 набор форм сохраняется, но электронная почта не отправляется. Есть ли способ отправить электронное письмо после перенаправления, чтобы пользователь не ждал обработки электронной почты до перенаправления страницы?
Спасибо.