Django Channels Tutorial 🔥: the most minimal Real Time app (not Chat) | Django WebSockets
HTML-код
- Опубликовано: 22 авг 2024
- This Django Channels tutorial is the most minimal example of how to use Django Channels to create a Real Time application, that uses Django and Websocket.
The main idea of this Django Channels tutorial is that Django generates numbers from 0 to 100, and send them to the front-end via opened WebSocket connection. And these numbers are rendered in real time without any actions from the User.
Minimum of JavaScript code.
Minimum of Python and Django code.
Minimum of HTML.
Just the core idea of how to use Websockets with Django.
And again this Django Channels tutorial - is the most minimal example of how to use Websockets with Django.
The WebSocket is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
To work with WebSockets with Django (on the server side) we have to use Django Channels - a special Python Django library.
This is an advanced Django tutorial
Follow me @:
Telegram: t.me/red_eyed_...
Twitter: / codereyed
Facebook: redeyedc...
=====================================
📎 The source code is available via Patreon:
/ most-minimal-45284762
=====================================
** Web Scraping course **
is available via Patreon here:
/ red_eyed_coder_club
or its landing:
red-eyed-coder...
➥ Please ➥ Like ➥ Comment ➥ Subscribe
Django Channels 3 tutorials ***
- Real Time Graph: • Django Channels Tutori...
- Real Time Broadcasting API response: • Django Channels, Celer...
** My Django 3 tutorial **
• Python Django Tutorial...
➥➥➥ SUBSCRIBE FOR MORE VIDEOS ➥➥➥
Red Eyed Coder Club is the best place to learn Python programming and Django:
Subscribe ⇢ / @redeyedcoderclub
Django Channels Tutorial - the most minimal Real Time app (not Chat) | Django WebSockets
• Django Channels Tutori...
#django #djangochannels #djangochannelstutorial #redeyedcoderclub #djangowebsockets
For anyone who isn't getting the "Starting ASGI/Channels" when starting up Django, but instead is getting the normal "Starting development server", I was able to resolve that problem by installing the *same* versions of django and channels to the virtual environment, because it looks like there was a change since this video came out.
I did
pip install django==3.1.4
pip install channels==3.0.2
The other dependencies didn't seem to be an issue even though they didn't match what was in the output of this video but in a few years it may be necessary to specify those as well.
Great video but tutorials like this ought to specify what versions they use, for future users.
For those who do not run "Starting ASGI/Channels",
1) remove "channels" (pip uninstall channels)
2) pip install channels["daphne"]
3) replace "channels" in INSTALLED_APPS with "daphne", and move it to the very top of the list
4) Many thanks to Oleg for developing the skill of finding and eliminating errors
Thanks a lot. It helps me.
Thanks a lot. I spent time in Cursor and chatGPT and still cannot get a useful solution for this.
Many thanks, kind sir.
Thanks a lot, good luck to you
You are an incredible human being, all the luck in the world to you!
Thank you for making a non-chat tutorial!
Thank you for watching!
@Red Eyed Coder Club I have a question. What would make this code/example work with multiple requests? I’m working on an app which has somewhat of a dashboard where multiple users can pick things from a list. This example works great but I was wondering what it takes for multiple users to interact
@@MrTdhillon try to follow the other Django Channels videos. It's just a very basic example.
What video should I make next? Any suggestions? *Write me in comments!*
Follow me @:
Telegram: t.me/red_eyed_coder_club
Twitter: twitter.com/CoderEyed
Facebook: fb.me/redeyedcoderclub
Help the channel grow! Please Like the video, Comment, SHARE & Subscribe!
I found several tutorials for Django Channels, and they were all so convoluted I was about to give up. Thank haven I found your tutorial, it is so well laid out and easy to follow, thank you so much!!!
Thank you very much!
That was already said but it's a real pleasure to find somebody who shows only a simple websocket. Thanks !
Thank you very much!
Man, that's how tutorials should be - bare minimum to run anything, no matter how ugly it is. Literally not a single unnecessary thing. Thanks, you rock.
Thank you
Le Bootstrap: Am I a joke to you?
@@jaideepshekhar4621 Didn't get your question
@@RedEyedCoderClub It's just a joke. Good video!
Олег, спасибо! Всегда круто и понятно!)
Thank you :)
In most of django channels tutorials they are just making the chat app using django channels documentation they dont even know what they are doing what they are importing why they are importing that middleware and as a beginner it was very confusing for me but your simple and basic video was very helpul and it explained me a lot So thank you for making this video.
Thank you very much!
Man. This was one of the best tutorials I ever came across. Thank you so much.
Thank you :)
This video is best for beginners. I am from Russia, but I got everything. Thanks!
Thank you very much!
Your voice is like watching django channels on discovery channel
Thanks for the tutorial
Thank you!
Thanks a lot! I really waited this topic so much! Glad to see it right here.
Thank you!
same dude
First example out of many that's clear to me. Thank you.
Thank you for the comment!
Thanks a lot for explaining so clearly the basics of django channels and web sockets.
Awesome stuff. It's so rare to find tutorials about Django Channels.
Thank you very much!
Thank you!
Really necessary minimum for understanding Django channels basics.
Thank you! Glad that it was helpful. Have a nice day!
yes, we need the spark and you just gave it. Awesome video.
Thank you very much!
yeah boiii, finally some minimal real time app
Thank you very much!
For everyone who wants to know the simple higher concept of Django Channels, I suggest you to watch this video first ! Then, you could continue other advanced technique with ease.
Thank you
Very useful tutorial. A lot of thanks.
Удивительно, я английский так сяк знаю, но тебя почему-то понимаю...)))) Спасибо за ролик!!!
Because of my pronunciation :)
@@RedEyedCoderClub, you have not so many flaws, though. There happens a slight confusion with British and American pronounciation (in some places, you read "r", despite it is implied that you will omit it in British (some kind of subtitution to a long "a"), or vice versa stretching vowels as Americans would do it) and too strong consonants (t, d, r mostly) when control over the tongue weakens a little.
Thanks for the video!
@@veirant5004 Thank you very much! I will work on it :)
This answered many questions i have. Thanks Red!
Thanks for watching!
Thank you
Thanks for watching!
Fantastic work!!! very simple and easy to follow. Thank you so much.
Thanks for watching!
thank you for this tutorial! It was very helpful to understand the basics of channels.
Thank you!
such a great tutorial! well thought approach for leaners new to channels concept!
Thank you very much!
Hello, nice video, do you use Redis? Is it necessary? thanks
Man the best tutorial that I find in youtube! Do you have a git rep link of this project?
Thanks!
Thank you very much, simple and understandable, I like yours 'визги' and 'асги' )
Thanks. I guess it's the right pronunciation according to the en.wikipedia.org/wiki/Web_Server_Gateway_Interface
@@RedEyedCoderClub let urlPath = '{{ url }}'
urlPath = urlPath.replace(/http|https/, 'ws')
const socket = new WebSocket(`${urlPath}ws/example`)
I think this JS websocket connection pattern more flexible, what's your opinion ? I am not an Python developer, used request.build_absolute_uri(),
yep, you are right
Really a was needed this thank you man
Thank you for your comment.
Thank you very much for Great example bro😊.
Thank you! :)
Thank you for the detailed info!
Thanks for watching!
Thank you a lot. I really wanted this!!
Thanks for watching! Have a nice day
Thank you, I used it for a real time trading app 👍
Thanks for watching and for your comment!
simple and complete .. love u ..
Thank you!
Great video, Thanks a lot. 🙌
Thanks for watching!
thx a lot sir, i know the differences of concept between http and web socket but your video tells how to implement, in a very clean way! really helps for newbie like me. But sir i have a question, if i wish to push data into multiple mobile apps (developed with flutter) at the same time, how can i do that?
Try to watch next video about broadcasting. It has the answer on you question.
Great tutorial, but I would like to understand its use-case - where do you think we could apply this logic for practically implementing it? Maybe "Chat" application? but here you are sending messages from server(django) to client(browser) using the "onmessage" method of WebSockets...and chat has to be between 2 clients(browser instances) I believe....Hence, if you could explain its practical use-case, maybe I will be able to relate it better...Anyways, thanks a lot for this tutorial.
This example has no practical use case. It's just an example of how to use Django Channels. Nothing more. I'll make more useful videos a bit later.
It can be very useful to simulate a real-time processes for learning purposes (or even be programs for managing such processes itself if requirements will be easy). Imagine to write an app for students to show them how to monitor water system in the city or temperature in a steel mill, or even getting the overall state of a car during driving. In all cases sensors (consumers) emit data and there's need to display such informations (as they are or processed) on screens in a control rooms and panels.
first thanks that was short to the point loved it now just asking doesn't this mean its now possible to call objects from the model in just similar manner or their is additional stuff ...
Not sure that got you correctly. Did you watch my other Django Channels videos?
1000th like🙂
Thank you :)
That is simple and undestandble. You are amazing teacher. Thank you so much.
Thank you!
man you nailed it
Thank you!
works great, but when I close the window and then reopen the same window, page doesn't work. I think I need another function when is disconnect
It's just the most minimal example. Did you try another videos of the series?
Thanks for this Amazing tut please how we can send data from view to consumer
Thank you. Didn't get what you want to achieve. Can you elaborate it a bit?
@@RedEyedCoderClub thanks for your reply I very much appreciate it,
I'm a newbie in Django I like your tutorials
I created a small app where anyone comes and types a keyword on the form (on the index.html page) and I created a python function that takes this keyword and scraps data from the web and returns the result to the user it returns many titles ['title1','title2','title3','title4', ......].
when I saw your real-time app I like it and I hope to display my scraped data like you do one by one don't wait for the function to scrap all titles.
This video is just a demonstration of very basic using of Django Channels. More complicated staff I put in other videos.
Did you watch my other videos about using of Django Channels?
They have the answer to your question. Consider of watching them, please.
Than you for your comment, and have a nice day!
thank you very much
Thanks for watching, and for the comment!
Thanks for the tutorial, I have a question, which address should I listen to if we talk about the server, and maybe what should I change in credentials for server work, not localhost? (in my case frontend at another server and it should listen for the websocket)
Sorry for the late answer. The websocket have to listen the IP of your server from where it gets data. The localhost is 127.0.0.1 IP address, and so there is no much difference here. But it's probably necessary to take into consideration the cross origin requests problem.
@@RedEyedCoderClub thanks for the answer, I already found out how to solve it. In settings.py I changed 127.0.0.1:8000 into 0.0.0.0:8000, and it starts work. And yeah, cross origin was too, but it wasn't big trouble)) Right now it's working, but a little bit slow(I send some requests to another server, for about 20 requests per minute), trying to find out how to make it faster
Amazing , tks a lot!
Thanks for watching and have a nice day!
Bro you just took the job of the Usestates in React..
Nice video, thanks
Thanks for watching!
Great video, Thanks a lot ^_^
Thank you!
Thank you!
Thanks for watching!
Wow, realy easy and tiny. 👍
Thank you!
Nice!
Thank you
very useful, tank you
Thank you!
Спасибо за ролик! У меня английски не на уровне, но я все понял
What if I refresh the page, there is no disconnect method in the consumer. Can you help me to understand what can I write in disconnect method.
In disconnect method usually is the logic of quitting from a group/channel and regarding stuff.
Do you know about rooms in SocketIO? Is there an equivalent to that in Channels?
I know about rooms. Did you watch my other Channels videos?
thank you so much
Thank you too!
Very cool. Will you make it in the future to support multiple clients?
The next video in the series with a project, that supports multiple clients.
@@RedEyedCoderClub Hey, looking forward to it! Thanks for replying. Have a nice day!
Thank you!
what if we refresh the page?? the connection is going to fail or it will reconnect??
It should reconnect but it won't, because it's a very basic example. Consider of watching my other Django Channels video.
It‘s a great tutorial.
Could you upload the demo code to the github?
Thank you a lot.
The project has the minimum of Python and JS code.
I have this error " Import "django.core.asgi" could not be resolved from source " when I write the ' django.core.asgi ' . How ı can solve this problem. pls help
What are you doing? What do you want to achieve?
Hi, can we scrape data and display data scrapped in real-time in place of your random numbers?
Hi, I have 4 videos about Django Channels.
The last one is about sending requests to an API (using Celery BTW), and rendering data in real-time.
The video:
ruclips.net/video/wos1uhnd3qM/видео.html
@@RedEyedCoderClub thanks, This is why you are the best
Thank you!
Thank you sir
Thank you too!
Listen failure: Couldn't listen on 127.0.0.1:8000: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted.
Check your code, please
Why can't you load the site in another tab? It's blocking any new requests?
It just can't handle the second request, because it's fully synchronous app.
Its great, but how to close the connection ?
Try to call the self.close() method in the connect method
Can anybody tell me why we do need to use json here? Like for what purposes we use that?
JSON is convenient data format. That's why.
6:10 video starts
Thanks for comment
Can asgi and wsgi run at the sametine ?
Yes, it's possible.
Can python be used as a client?
Actually no, but Python code can be compiled to JS, and this allows to use Python on frontent.
thanx
спасибо большое
You're welcome
How do I pass that data to the live html?
It will work the same way in production
why do you use redis?
Why not to use Redis?
How can we use the same on server, its not connecting
This example is not for production, consider watching of my other Django Channels videos.
Thanks for comment
please anyone
ERROR is
django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'startup.asgi'
check your code or start a new project from scratch. I've got the same bug one time.
Ok but can you make a scalable video chatting app with this
I'll make a video about chatting app, but it'll be a bit later. It'll be the video #5 in the Channels topic.
and for deploy this project?
Maybe next time
jared yambao gusto mag lig pero wala pang comment
its not working with https
:D It's just an example, demonstrating the basic principle.
@@RedEyedCoderClub ok. how to remove client limitations?
Когда будут видосы на русском?
Maybe later
Please make Django chat app
Of course, but a bit later
@@RedEyedCoderClub by the way your content is amazing keep it up!!!
Thank you!
Are you russian person?
Я не знаю можно ли размещать ссылки на канал в комментариях. поэтому просто посоветую набрать Олег Молчанов в поиске и найдешь его русскоязычный канал
@@user-tl4ur8ib1l да ладно это он? XDDDDD
yep, it's him
o please anyone help
try to check your code