Error: Your View Return An Httpresponse Object. It Returned An Unawaited Coroutine Instead. You May Need To Add An 'await' Into Your View
I am working on a Django Project where i add an event to the database and then send an email to all the subscribers after adding event. I want to do the sending email task async, i
Solution 1:
The problem appears to be that the login_required
decorator doesn't currently support async views (see https://code.djangoproject.com/ticket/31949). One solution described in that ticket is to wrap the function before the decorator and then unwrap it:
import asyncio
from asgiref.sync import async_to_sync, sync_to_async
from django.contrib.auth.decorators import login_required
@sync_to_async@login_required(login_url='/login/')@async_to_syncasyncdefadd_event_view(request):
...
Post a Comment for "Error: Your View Return An Httpresponse Object. It Returned An Unawaited Coroutine Instead. You May Need To Add An 'await' Into Your View"