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

Комментарии • 197

  • @seanicus100
    @seanicus100 Год назад +3

    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.

  • @user-iq6qy3rw2l
    @user-iq6qy3rw2l Год назад +4

    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

    • @jasmeetpabla378
      @jasmeetpabla378 Год назад

      Thanks a lot. It helps me.

    • @javierzheng5979
      @javierzheng5979 Год назад

      Thanks a lot. I spent time in Cursor and chatGPT and still cannot get a useful solution for this.

    • @ritiktyagi1926
      @ritiktyagi1926 Год назад

      Many thanks, kind sir.

    • @khoaavan8075
      @khoaavan8075 11 месяцев назад

      Thanks a lot, good luck to you

    • @zholdanimelyrics4276
      @zholdanimelyrics4276 10 месяцев назад

      You are an incredible human being, all the luck in the world to you!

  • @MrTdhillon
    @MrTdhillon 3 года назад +45

    Thank you for making a non-chat tutorial!

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +3

      Thank you for watching!

    • @MrTdhillon
      @MrTdhillon 3 года назад +1

      @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

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +1

      @@MrTdhillon try to follow the other Django Channels videos. It's just a very basic example.

  • @RedEyedCoderClub
    @RedEyedCoderClub  3 года назад +5

    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!

  • @hmoazed
    @hmoazed 3 года назад +9

    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!!!

  • @ADL1422
    @ADL1422 2 года назад +2

    That was already said but it's a real pleasure to find somebody who shows only a simple websocket. Thanks !

  • @Saheryk
    @Saheryk 2 года назад +1

    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.

  • @MrYoklmn
    @MrYoklmn 3 года назад +17

    Олег, спасибо! Всегда круто и понятно!)

  • @AdityaSingh-qc4xd
    @AdityaSingh-qc4xd 3 года назад +3

    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.

  • @afrasiyabkakakhel4643
    @afrasiyabkakakhel4643 2 года назад +2

    Man. This was one of the best tutorials I ever came across. Thank you so much.

  • @artemdyrdin6150
    @artemdyrdin6150 3 года назад +1

    This video is best for beginners. I am from Russia, but I got everything. Thanks!

  • @mrigendraprasad1877
    @mrigendraprasad1877 3 года назад +3

    Your voice is like watching django channels on discovery channel
    Thanks for the tutorial

  • @TdadadT9
    @TdadadT9 3 года назад +3

    Thanks a lot! I really waited this topic so much! Glad to see it right here.

  • @Tuxcz
    @Tuxcz Год назад

    First example out of many that's clear to me. Thank you.

  • @jasmeetpabla378
    @jasmeetpabla378 Год назад

    Thanks a lot for explaining so clearly the basics of django channels and web sockets.

  • @FreeDomSy-nk9ue
    @FreeDomSy-nk9ue 3 года назад

    Awesome stuff. It's so rare to find tutorials about Django Channels.

  • @ivanmaslennikov8415
    @ivanmaslennikov8415 2 года назад

    Thank you!
    Really necessary minimum for understanding Django channels basics.

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Thank you! Glad that it was helpful. Have a nice day!

  • @bipulkalita5780
    @bipulkalita5780 2 года назад

    yes, we need the spark and you just gave it. Awesome video.

  • @BMAKAUSTUBHVERMA
    @BMAKAUSTUBHVERMA 2 года назад

    yeah boiii, finally some minimal real time app

  • @RichardFirOey
    @RichardFirOey 3 года назад +1

    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.

  • @tazul8
    @tazul8 8 месяцев назад

    Very useful tutorial. A lot of thanks.

  • @user-is2wd4fn2j
    @user-is2wd4fn2j 3 года назад +1

    Удивительно, я английский так сяк знаю, но тебя почему-то понимаю...)))) Спасибо за ролик!!!

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Because of my pronunciation :)

    • @veirant5004
      @veirant5004 2 года назад

      @@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!

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      @@veirant5004 Thank you very much! I will work on it :)

  • @klduck2468
    @klduck2468 3 года назад

    This answered many questions i have. Thanks Red!

  • @Letop5suryoutube
    @Letop5suryoutube 3 года назад +1

    Thank you

  • @MadhanMohanReddyB
    @MadhanMohanReddyB 3 года назад

    Fantastic work!!! very simple and easy to follow. Thank you so much.

  • @AbzalAmeer
    @AbzalAmeer 3 года назад

    thank you for this tutorial! It was very helpful to understand the basics of channels.

  • @forentrepreneurs3852
    @forentrepreneurs3852 2 года назад

    such a great tutorial! well thought approach for leaners new to channels concept!

  • @dchiquinho4885
    @dchiquinho4885 10 месяцев назад

    Hello, nice video, do you use Redis? Is it necessary? thanks

  • @vivo0304
    @vivo0304 Год назад

    Man the best tutorial that I find in youtube! Do you have a git rep link of this project?
    Thanks!

  • @LNMaster_
    @LNMaster_ 3 года назад

    Thank you very much, simple and understandable, I like yours 'визги' and 'асги' )

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +1

      Thanks. I guess it's the right pronunciation according to the en.wikipedia.org/wiki/Web_Server_Gateway_Interface

    • @LNMaster_
      @LNMaster_ 3 года назад +1

      @@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(),

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      yep, you are right

  • @brahimboughanam1662
    @brahimboughanam1662 3 года назад

    Really a was needed this thank you man

  • @nirutg5130
    @nirutg5130 2 года назад

    Thank you very much for Great example bro😊.

  • @robertcepero5598
    @robertcepero5598 3 года назад

    Thank you for the detailed info!

  • @ommahajan1
    @ommahajan1 3 года назад

    Thank you a lot. I really wanted this!!

  • @davidmaillot4283
    @davidmaillot4283 2 года назад

    Thank you, I used it for a real time trading app 👍

  • @noobstack3498
    @noobstack3498 3 года назад

    simple and complete .. love u ..

  • @ehsanmatari2819
    @ehsanmatari2819 3 года назад

    Great video, Thanks a lot. 🙌

  • @lunaRdeltaY
    @lunaRdeltaY 2 года назад

    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?

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Try to watch next video about broadcasting. It has the answer on you question.

  • @codedjango
    @codedjango 3 года назад

    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.

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +3

      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.

    • @marcinszydowski5563
      @marcinszydowski5563 2 года назад

      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.

  • @katata4742
    @katata4742 2 года назад

    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 ...

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Not sure that got you correctly. Did you watch my other Django Channels videos?

  • @rajeshthoomu3297
    @rajeshthoomu3297 2 года назад

    1000th like🙂

  • @rezakhalafi528
    @rezakhalafi528 Год назад

    That is simple and undestandble. You are amazing teacher. Thank you so much.

  • @nootherkyle
    @nootherkyle 2 года назад

    man you nailed it

  • @gus_gus_
    @gus_gus_ 2 года назад

    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

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      It's just the most minimal example. Did you try another videos of the series?

  • @geektom8898
    @geektom8898 2 года назад

    Thanks for this Amazing tut please how we can send data from view to consumer

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад +1

      Thank you. Didn't get what you want to achieve. Can you elaborate it a bit?

    • @geektom8898
      @geektom8898 2 года назад

      @@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.

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      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!

  • @Mrshorts_cut
    @Mrshorts_cut 2 года назад

    thank you very much

  • @user-wl6gd5xh1t
    @user-wl6gd5xh1t 2 года назад

    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)

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      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.

    • @user-wl6gd5xh1t
      @user-wl6gd5xh1t 2 года назад

      @@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

  • @thiagocnunes
    @thiagocnunes 3 года назад

    Amazing , tks a lot!

  • @franco_bsnss7482
    @franco_bsnss7482 29 дней назад

    Bro you just took the job of the Usestates in React..

  • @fabianhaukhopland6713
    @fabianhaukhopland6713 3 года назад

    Nice video, thanks

  • @Aiminsun
    @Aiminsun 3 года назад

    Great video, Thanks a lot ^_^

  • @aashayamballi
    @aashayamballi 3 года назад

    Thank you!

  • @guenterbailey5974
    @guenterbailey5974 2 года назад

    Wow, realy easy and tiny. 👍

  • @Tom.A.
    @Tom.A. 3 года назад

    Nice!

  • @radeshf
    @radeshf 2 года назад

    very useful, tank you

  • @bahakulbarakov494
    @bahakulbarakov494 3 года назад +1

    Спасибо за ролик! У меня английски не на уровне, но я все понял

  • @mukulkumar8188
    @mukulkumar8188 3 года назад

    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.

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      In disconnect method usually is the logic of quitting from a group/channel and regarding stuff.

  • @OnyxBloodStone
    @OnyxBloodStone 3 года назад

    Do you know about rooms in SocketIO? Is there an equivalent to that in Channels?

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      I know about rooms. Did you watch my other Channels videos?

  • @mahmoudbechki8210
    @mahmoudbechki8210 3 года назад

    thank you so much

  • @omarnomad
    @omarnomad 3 года назад

    Very cool. Will you make it in the future to support multiple clients?

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +2

      The next video in the series with a project, that supports multiple clients.

    • @omarnomad
      @omarnomad 3 года назад

      @@RedEyedCoderClub Hey, looking forward to it! Thanks for replying. Have a nice day!

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      Thank you!

  • @mozzaminamdar7143
    @mozzaminamdar7143 Год назад

    what if we refresh the page?? the connection is going to fail or it will reconnect??

    • @RedEyedCoderClub
      @RedEyedCoderClub  Год назад

      It should reconnect but it won't, because it's a very basic example. Consider of watching my other Django Channels video.

  • @caipeiyuan5391
    @caipeiyuan5391 3 года назад

    It‘s a great tutorial.
    Could you upload the demo code to the github?
    Thank you a lot.

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      The project has the minimum of Python and JS code.

  • @ugursakarya8995
    @ugursakarya8995 2 года назад

    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

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      What are you doing? What do you want to achieve?

  • @alexdin1565
    @alexdin1565 2 года назад

    Hi, can we scrape data and display data scrapped in real-time in place of your random numbers?

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад +1

      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

    • @alexdin1565
      @alexdin1565 2 года назад

      @@RedEyedCoderClub thanks, This is why you are the best

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Thank you!

  • @nagarajkalakutagi5717
    @nagarajkalakutagi5717 3 года назад

    Thank you sir

  • @supritkumar2624
    @supritkumar2624 3 года назад

    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.

  • @AliAbdullah-oi3wc
    @AliAbdullah-oi3wc 3 года назад

    Why can't you load the site in another tab? It's blocking any new requests?

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад +1

      It just can't handle the second request, because it's fully synchronous app.

  • @liorbm1
    @liorbm1 2 года назад

    Its great, but how to close the connection ?

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Try to call the self.close() method in the connect method

  • @devmrnecro4215
    @devmrnecro4215 3 года назад

    Can anybody tell me why we do need to use json here? Like for what purposes we use that?

  • @rakeshnagarajan7701
    @rakeshnagarajan7701 2 года назад

    6:10 video starts

  • @technicalilm8999
    @technicalilm8999 2 года назад

    Can asgi and wsgi run at the sametine ?

  • @noru.sketch
    @noru.sketch 2 года назад

    Can python be used as a client?

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Actually no, but Python code can be compiled to JS, and this allows to use Python on frontent.

  • @lukaszromanowski8285
    @lukaszromanowski8285 3 года назад

    thanx

  • @vitalii7672
    @vitalii7672 2 года назад

    спасибо большое

  • @jansgreen4650
    @jansgreen4650 2 года назад

    How do I pass that data to the live html?

  • @TheUltimateNoobHD
    @TheUltimateNoobHD Год назад

    why do you use redis?

  • @athuldas8689
    @athuldas8689 2 года назад

    How can we use the same on server, its not connecting

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      This example is not for production, consider watching of my other Django Channels videos.

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      Thanks for comment

  • @naeemnawaz4590
    @naeemnawaz4590 3 года назад

    please anyone
    ERROR is
    django.core.exceptions.ImproperlyConfigured: Cannot import ASGI_APPLICATION module 'startup.asgi'

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      check your code or start a new project from scratch. I've got the same bug one time.

  • @aayushpatil7514
    @aayushpatil7514 3 года назад

    Ok but can you make a scalable video chatting app with this

    • @RedEyedCoderClub
      @RedEyedCoderClub  3 года назад

      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.

  • @UMBERTOartS7
    @UMBERTOartS7 3 года назад

    and for deploy this project?

  • @alfonzotamano6209
    @alfonzotamano6209 8 месяцев назад

    jared yambao gusto mag lig pero wala pang comment

  • @alexle3598
    @alexle3598 2 года назад

    its not working with https

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      :D It's just an example, demonstrating the basic principle.

    • @alexle3598
      @alexle3598 2 года назад

      @@RedEyedCoderClub ok. how to remove client limitations?

  • @egorkomarov4719
    @egorkomarov4719 3 года назад +1

    Когда будут видосы на русском?

  • @user-bc2ec6dg4e
    @user-bc2ec6dg4e 3 года назад

    Please make Django chat app

  • @bahakulbarakov494
    @bahakulbarakov494 3 года назад

    Are you russian person?

    • @user-tl4ur8ib1l
      @user-tl4ur8ib1l 3 года назад

      Я не знаю можно ли размещать ссылки на канал в комментариях. поэтому просто посоветую набрать Олег Молчанов в поиске и найдешь его русскоязычный канал

    • @bahakulbarakov494
      @bahakulbarakov494 3 года назад

      @@user-tl4ur8ib1l да ладно это он? XDDDDD

    • @RedEyedCoderClub
      @RedEyedCoderClub  2 года назад

      yep, it's him

  • @naeemnawaz4590
    @naeemnawaz4590 3 года назад

    o please anyone help