'The view didn't return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an 'await' into your view

Python: 3.8 Django: 3.2.

I am building a django app following this article(ERROR: Your view return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an 'await' into your view)

Here is my code:

import asyncio

This is the view

async def get_smokables():
    print("Getting smokeables...")
    await asyncio.sleep(2)

async def save_setting(request):
   await asyncio.gather(*[get_smokables()])
   return HttpResponse('ok')

Run command:

uvicorn config.asgi:application --reload

When I tried above code, it says "The view views.save_setting didn't return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an 'await' into your view."



Sources

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

Source: Stack Overflow

Solution Source