# Run Django app and also connect to a websocket

**URL:** <https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863>\
**Category:** Using Django\
**Created:** [June 8, 2020, 9:23pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863 "2020-06-08T21:23:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 8, 2020, 9:23pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/1 "2020-06-08T21:23:34Z")

</div>

I want to run my Django app as normal but at the same time also connect to a websocket and use the data that is coming from there. Is it possible to do both of these at the same time using ASGI?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 8, 2020, 11:18pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/2 "2020-06-08T23:18:13Z")

</div>

If you’re looking for a websocket connection, you want to look at [Channels](https://channels.readthedocs.io/en/latest/).

---

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 9, 2020, 8:09am UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/3 "2020-06-09T08:09:05Z")

</div>

I’ve looked at Channels and it seems to add a huge amount of architectural complexity for what should maybe just be a small feature? I would prefer to avoid it.

I was under the impression that ASGI would obsolete Channels? Is that false?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 9, 2020, 12:45pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/4 "2020-06-09T12:45:02Z")

</div>

There may be some overlap of functionality between ASGI and Channels, but it won’t obsolete it - there are some distinctions between the two. Current Django/ASGI is still built around the “request/response” model, even if the Views are starting to be able to process asynchronously.

That “small feature” as you describe it is a completely different protocol - you’re no longer working with discrete requests but with continual data streams creating event-driven interactions.

Ken

---

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 9, 2020, 3:39pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/5 "2020-06-09T15:39:02Z")

</div>

I’m not sure whether it’s fully incompatible. Or at least I hope there’s a way.

I think I’ve seen a tutorial run a websocket server in the same process by patching `asgi.py`. I guess that works by multiplexing on the same host:port combination based on what you get?

The Django docs hint at being able to compose apps using ASGI but it’s a throw away sentence more than anything else. (Anything more on that? Or could somebody help me add it?)

For my use case, I need my app to be able to connect to a websocket in parallel to running the web app. Maybe that’ll be easier by composing one `await` loop next to the main Django app?

---

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 9, 2020, 7:28pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/6 "2020-06-09T19:28:30Z")

</div>

Specifically there’s this tutorial: [https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-extra-dependencies-2f6h](https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-extra-dependencies-2f6h)

---

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 9, 2020, 7:29pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/7 "2020-06-09T19:29:35Z")

</div>

There’s this tutorial that does Websockets from just Django: [https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-extra-dependencies-2f6h](https://dev.to/jaydenwindle/adding-websockets-to-your-django-app-with-no-extra-dependencies-2f6h)

---

<div class="post-metadata">

**Author:** ![duhfrazee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/duhfrazee/32/1398_2.png) [@duhfrazee](https://forum.djangoproject.com/u/duhfrazee)\
**Post date:** [June 12, 2020, 11:34am UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/8 "2020-06-12T11:34:37Z")

</div>

Any luck on this? Did you end up following something similar to the article you posted? I’m trying to accomplish something very similar in my django app.

---

<div class="post-metadata">

**Author:** ![alper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/alper/32/1370_2.png) [@alper](https://forum.djangoproject.com/u/alper)\
**Post date:** [June 12, 2020, 12:43pm UTC](https://forum.djangoproject.com/t/run-django-app-and-also-connect-to-a-websocket/2863/9 "2020-06-12T12:43:55Z")

</div>

You should track the other conversation here: [Add a websocket client to Django (not a server)](https://forum.djangoproject.com/t/add-a-websocket-client-to-django-not-a-server/2916/11)
