About Turning Any Function into Async Function
ASGI configurations support both types of views: synchronous (normal) and asynchronous (similar to threads, allowing long execution time).
To convert any function to asynchronous, use this technique:
from asgiref.sync import sync_to_async
from django.shortcuts import render
from .helpers import helper_function
async timely_view(request, param1, param2):
result = None
if request.method == "POST":
result = await sync_to_async(
helper_function, thread_sensitive=True
)(param1=param1, param2=param2)
return render(request, "myapp/timely_view.html", {"result": result})
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 ASGI
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.