Thursday, August 12, 2021

Re: Async Help Needed

The example you presented should Just Work - that error generally only occurs if you return an un-awaited coroutine, which if you're just returning a response, should be impossible.

What version of Python and Django are you running?

Andrew

On Thu, Aug 12, 2021, at 11:03 AM, Steven Mapes wrote:
Does anyone have some links to good guides on getting asnyc to work with Django? I have a use case where I really need to have a view give an async response but I can't get even the most basic of examples working.

I've tried the examples from https://testdriven.io/blog/django-async-views/ with a simple view of:

async def test_view(request):
    return HttpResponse("Hello, async Django!")

I've installed uvicorn and am running it with  uvicorn my_project.asgi:application --reload

My sync views work as expected but the async one just returns an error of "The view sample.views.test_view didn't return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an 'await' into your view."



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

No comments:

Post a Comment