相关疑难解决方法(0)

Django中如何调用异步函数?

以下不执行foo并给出 RuntimeWarning: coroutine 'foo' was never awaited

# urls.py

async def foo(data):
    # process data ...

@api_view(['POST'])
def endpoint(request):
    data = request.data.get('data')
    
    # How to call foo here?
    foo(data)

    return Response({})
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework python-3.6 django-3.0

12
推荐指数
2
解决办法
2万
查看次数