Note: This post was originally published on my blog.
Now that Django 3.0 ships with ASGI support out of the box, adding Websockets to your Django ...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for this post. I have a question, how possible send a message to WebSocket from Django views? by above I just can do something just when a client sends me a message.
I have an implementation for this, maybe you would like to take a look at it!
Basically, the queue can be change by any other type of queue which allows you to exchange data between routines and threads (Each requests to django_application are new threads, you can check that, requests to websocket_application share the same thread)
Did someone found a good solution? The above information is great, but i can do something like that with ajax and json-response. A way from view to the client-websockets is much more interesting. THX!
That's an excellent question, and I'd like to know the answer, let me know if you find out a way
Hi, I am encountering errrors when creating a websocket connection,
And the uvicorn request says:
"WARNING: Unsupported upgrade request."
How do I fix this issue?
Thanks.
And also this
pip install uvicorn
did not deal with WebSocket configuration.
config.ws_protocol_class is None
so in L:264 you will get a warning.
try: pip install uvicorn[standard]
See ref
Thanks for your post, i have a question, how i can use with nginx, i am trying deploy my project and i have the next case, the event['type'] is http.request i need websocket.connect, i belive is by my nginx configuration but i am not sure, my configuration is
Hi Jayden!
First of all I'd like to thank you for this amazing post!
I've been following this post step by step and I'm getting an error when I'm trying to start up de Uvicorn server, which I guess it's related to a breaking change on a dependency.
The error is the following
"module 'websockets' has no attribute 'WebSocketServerProtocol'"
Do you know which is the path to continue?
I realized that running it from the same directory that the asgi.py file it works, so it looks like I'm doing something wrong with the path :/
Running "uvicorn asgi:application" from the asgi file directory works
Running "uvicorn websockets.asgi:application" from the project's directory does not work (my project is called websockets)
Well I was able to find the problem, your project must not be called websockets.
Thank you so much for sharing this great piece of knowledge. I've been struggling with Websockets and now I feel that I've found a path. And I'm really glad to see this path through Django that I love a lot.
Thanks for this writeup Jayden. However, I'm wondering if this the right approach, and how maintainable is it. I feel I'd wait for things to settle a bit instead of reinventing the wheel. See github.com/django/deps/blob/master...
This is a fantastic article. Thank you. How would you use a django database call with this? For example, User.objects.get( pk=1 )?
This tutorial doesnt work for me. I am getting this traceback:
"TypeError: asgi_send() missing 1 required positional argument: 'message'"
Hi Jayden!
How can we use same websocket for multiple clients so that multiple users could chat to each other?