0

Here is my post_save method:

from asgiref.sync import sync_to_async

@receiver(post_save, sender=SubmissionDetails)
def create_submission_email(sender, instance, created, **kwargs):
    if created:
        data = sync_to_async(call_submssion_email(instance))

def call_manuscript_submssion_email(instance):
    print("Hi")
    message = '''Submitted with the title, <br>
    {0}'''.format(instance.title)
    subject = 'Article Submitted'
    to_address = 'example@gmail.com'
    from_address = "from@mail.example.com"
    msg = EmailMessage(
                    subject, message,from_address,[to_address]
                    )
    msg.content_subtype = "html"
    msg.send()

The problem is while submitting the form, the user has to wait till email is sent to see the results. I am using django 3.0 with some async support.

Amiya Behera
  • 2,210
  • 19
  • 32

1 Answers1

1

Asynchronous support

New in Django 3.0

Django has developing support for asynchronous (“async”) Python, but does not yet support asynchronous views or middleware; they will be coming in a future release.

There is limited support for other parts of the async ecosystem; namely, Django can natively talk ASGI, and some async safety support.

Django Asynchronous support official


You can use Django Channels or Celery for your asynchronous code.

You can also check How are Django channels different than celery?