# AssertionError: Expected a \`Response\`, \`HttpResponse\` or \`HttpStreamingResponse\` to be returned from the view, but received a \`\<class 'coroutine'\>\`

**URL:** <https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326>\
**Category:** Async/Channels\
**Created:** [July 16, 2023, 7:14am UTC](https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326 "2023-07-16T07:14:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToolmanP](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/toolmanp/32/14827_2.png) [@ToolmanP](https://forum.djangoproject.com/u/ToolmanP)\
**Post date:** [July 16, 2023, 7:14am UTC](https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326/1 "2023-07-16T07:14:47Z")

</div>

I follow the instruction posted [here](https://docs.djangoproject.com/en/4.2/topics/async/)

> Django has support for writing asynchronous (“async”) views, along with an entirely async-enabled request stack if you are running under [ASGI](https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/). Async views will still work under WSGI, but with performance penalties, and without the ability to have efficient long-running requests.

I have started the application using dyphne and define it in settings.py

```python
INSTALLED_APPS = [
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'chat',
    'oauth',
    'corsheaders',
    'rest_framework',
]
ASGI_APPLICATION = 'sample.asgi.application'

```

and wrap my views with async def with something like

```python
@api_view(['GET', 'POST'])
@authentication_classes([SessionAuthentication])
@permission_classes([IsAuthenticated]) 
async def sessions(request):
    if request.method == 'GET':
        user = request.user  
        sessions = [session async for session in Session.objects.filter(user=user)]
        return JsonResponse(SessionSerializer(sessions,many=True).data, safe=False)
    elif request.method == 'POST':
        user = request.user
        session = await Session.objects.acreate(name='new session', user=user)
        return JsonResponse(SessionSerializer(session).data)

```

I have set everything up and it shows it runs under asgi correctly

```console
Starting ASGI/Daphne version 4.0.0 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
HTTP/2 support not enabled (install the http2 and tls Twisted extras)

```

But It just panics with

```console
AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'coroutine'>`

```

Do i miss something to be configured here? 🙃

---

<div class="post-metadata">

**Author:** ![ToolmanP](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/toolmanp/32/14827_2.png) [@ToolmanP](https://forum.djangoproject.com/u/ToolmanP)\
**Post date:** [July 16, 2023, 7:41am UTC](https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326/2 "2023-07-16T07:41:27Z")

</div>

I’ve solved problem by changing api\_view from `rest_framework.decorators.apiview` to `ardf.decorators.apiview`

---

<div class="post-metadata">

**Author:** ![dataScientistMS](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/datascientistms/32/17818_2.png) [@dataScientistMS](https://forum.djangoproject.com/u/dataScientistMS)\
**Post date:** [December 16, 2023, 8:14am UTC](https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326/4 "2023-12-16T08:14:40Z")

</div>

Hi, whats ardf, and how you install it ?

---

<div class="post-metadata">

**Author:** ![dataScientistMS](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/datascientistms/32/17818_2.png) [@dataScientistMS](https://forum.djangoproject.com/u/dataScientistMS)\
**Post date:** [December 16, 2023, 8:23am UTC](https://forum.djangoproject.com/t/assertionerror-expected-a-response-httpresponse-or-httpstreamingresponse-to-be-returned-from-the-view-but-received-a-class-coroutine/22326/5 "2023-12-16T08:23:41Z")

</div>

Its a custom package made by [em1208](https://github.com/em1208/adrf) on github, and its not `ardf` but `adrf`. You can install it with `pip install adrf`.
