'Django 4 template check if user is authenticated using async view

Is there any way to check if a user is authenticated in the Django template using async view? I am having the errors SynchronousOnlyOperation when I do {% if user.is_authenticated %} in my template.

I know there is the option DJANGO_ALLOW_ASYNC_UNSAFE but the doc says it's not safe. So I am wondering if there is a safer method.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source