I try to use an async view that is decorated somewhere by login_required.
Currently i decorate it in my urls.py
urls.py:
from . import views
from django.urls import path
from django.contrib.auth.decorators import login_required
urlpatterns = [
path('', login_required(views.my_view), name='my_view'),
]
views.py:
async def my_view(request):
return render(request, 'app/test.html', context={})
When tested it I get an error that this view would return an unawaited coroutine
When render is awaited, it tells me that i cannot await a http response.
views.py:
@async_to_sync
async def my_view(request):
return render(request, 'app/test.html', context={})
Seems to work but,
in my understanding @async_to_sync should turn it synchronus, but executes it asyncronous?
edit:
without login_required @async_to_sync does not seem to be required and it works.
what is the the proper way to do it?