我不知道我做错了什么
我无法获取数据库数据。
class AsyncChatConsumer(AsyncWebsocketConsumer):
async def receive(self, text_data):
users = await self.get_users()
for user in users:
print(user.id)
@database_sync_to_async
def get_users(self):
return User.objects.all()django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.我查的资料和公文都是这样写的。
但是为什么我会得到一个错误呢?
发布于 2021-07-26 14:33:35
您的问题在stackoverflow上重复:
这里已经解释过了:Django Channels Error: you cannot use AsyncToSync in the same thread as an async event loop
https://stackoverflow.com/questions/68525146
复制相似问题