Django 4.0 ASGI application returns 500 error on async view with database queries
I'm stuck on something that should probably be simple. I'm working on a Django 4.0 project that uses async views, and I've run into a 500 Internal Server Error when trying to perform database queries within an async view... The view is supposed to retrieve user data and return it as JSON. Here's the code for my async view: ```python from django.http import JsonResponse from django.views import View from .models import User class AsyncUserView(View): async def get(self, request): users = await User.objects.all() # This line causes the error user_data = [{'id': user.id, 'name': user.name} for user in users] return JsonResponse(user_data, safe=False) ``` When I try to access this view, I get the following error in the console: ``` TypeError: 'coroutine' object is not subscriptable ``` I've tried using `await` with the `all()` method thinking it would work, but it seems Django's ORM is not fully compatible with async views like this. I also checked that my database settings are set up correctly for async support in `settings.py`: ```python DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'mydatabase', 'USER': 'myuser', 'PASSWORD': 'mypassword', 'HOST': 'localhost', 'PORT': '5432', } } ``` I've also looked into using Django Channels for handling async operations, but I'm unsure if that's necessary just for retrieving data. Is there a way to get this to work with the existing ORM in an async view without running into this coroutine error? Any suggestions would be appreciated! For context: I'm using Python on macOS. For context: I'm using Python on CentOS. Could someone point me to the right documentation?