# How should i write a view using Django 3 and async/await?

**URL:** <https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238>\
**Category:** Using Django\
**Created:** [September 14, 2019, 1:57pm UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238 "2019-09-14T13:57:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![edvm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/edvm/32/213_2.png) [@edvm](https://forum.djangoproject.com/u/edvm)\
**Post date:** [September 14, 2019, 1:57pm UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238/1 "2019-09-14T13:57:33Z")

</div>

Hi, i’m trying to use `async/await` on Django 3.1. I naively tryed to write a view like:

```auto
from django.http import HttpResponse
import asyncio

async def bar(request):
    await test_1()
    return HttpResponse("Fooooooooo")

async def test_1():
    print('Hello!!')
    await asyncio.sleep(5)
    print('Bye!!')

```

but i’m getting an exception: `'coroutine' object has no attribute 'get'`  
Could you please give me some hints where too look up? (links to docs, or files in the source code? (i cloned `master` to see if i could find some glues, but still searching)

---

<div class="post-metadata">

**Author:** ![andrewgodwin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/andrewgodwin/32/2_2.png) [@andrewgodwin](https://forum.djangoproject.com/u/andrewgodwin)\
**Post date:** [September 14, 2019, 3:29pm UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238/2 "2019-09-14T15:29:25Z")

</div>

Django doesn’t have support for async views yet - that’s still in development in a pull request ([https://github.com/django/django/pull/11650](https://github.com/django/django/pull/11650)) and it’ll be a while until I can solve enough of the edge cases to get it to land.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [September 14, 2019, 4:04pm UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238/3 "2019-09-14T16:04:02Z")

</div>

@edvm Thanks to your question I was inspired to try converting my “single file Django” app to ASGI. See my new blog post: [https://adamj.eu/tech/2019/09/14/a-single-file-async-django-app/](https://adamj.eu/tech/2019/09/14/a-single-file-async-django-app/)

As Andrew says he hasn’t found a way to do async views yet, but you can combine Django with another framework for asynchronous paths (e.g. Websockets). See the end of my post.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![edvm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/edvm/32/213_2.png) [@edvm](https://forum.djangoproject.com/u/edvm)\
**Post date:** [September 14, 2019, 11:07pm UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238/4 "2019-09-14T23:07:55Z")

</div>

Thanks a lot @adamchainz for your mention in your blog post and the post itself (i’ll try it!)

---

<div class="post-metadata">

**Author:** ![edvm](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/edvm/32/213_2.png) [@edvm](https://forum.djangoproject.com/u/edvm)\
**Post date:** [September 15, 2019, 12:55am UTC](https://forum.djangoproject.com/t/how-should-i-write-a-view-using-django-3-and-async-await/238/5 "2019-09-15T00:55:56Z")

</div>

Thank you @andrewgodwin . I’ll check it out. 👌
