Django Realtime Chat App Tutorial - Simple Python Django Tutorial With Channels And Redis

Поделиться
HTML-код
  • Опубликовано: 22 авг 2024
  • Learn how to build a simple realtime chat application using Django, Python, Web sockets, Channels and Redis.
    To do list for this Django tutorial
    -Set up the environment and install everything
    -Create the front page
    -Create the room page
    -Connecting to a room
    -Sending messages to each other
    -Storing messages in a database
    Messages are stored in a database, so it's even possible to see old messages.
    To connect with the backend, I use Web Sockets (Vanilla JavaScript). To add async support to Django, I use Channels.
    Redis is used as a in-memory cache for Channels.
    The chat we build in this Django tutorial is very basic, and it's mostly to demonstrate how it can be done.
    The code we put together here, can be used as a bare for something much bigger like a Slack clone and similar. But that requires a lot of work of course.
    If you want to read this tutorial instead, check it out here: codewithstein....
    ---
    Important links
    Github: github.com/Ste...
    Discord: / discord
    Patreon: / codewithstein
    Twitter: / codewithstein
    Website: codewithstein.com
    ---
    #codewithstein #django #djangochat #channels #redis #learndjango #javascript #python #websockets

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

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

    Woohooo... Finally.
    Been waiting for this!

  • @Bebunzenho
    @Bebunzenho 8 месяцев назад +1

    amazing video, still useful in 2023

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

    What an excellent tutorial!!!! Can't wait for the new advanced version to drop soon!!

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

      Thanks :-D Sounds great, it will probably be a premium course though ;-)

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

    Excellent, a few months ago asked for this tutorial finally you are started, thank you so much for the tutorial

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

      You're welcome :-) Thanks for always being a loyal subscriber :-D

  • @ahmeddoudou2262
    @ahmeddoudou2262 Год назад +1

    Thanks a lot, Bro! Awesome tutorial. its my first time to see you on RUclips, you are great

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

    Another excellent tutorial regarding how to build a simple realtime chat application using Django, Web sockets, Channels and Redis.

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

      Thank you Dale :-D

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

      are deploying on server ? not working /ws = /, how to solutions ?

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

      Yes, you can deploy this. I dont understand what you are asking for? 🤷🏼‍♂️

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

      It wasn't me that asked that question.
      Thanks

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

      I know Dale ☺️ the commenting system here just isn’t the best :/

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

    I have been looking for an up-to-date tutorial on this. Thanks

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

    Greetings, Stein is at it again, smiles, awesome!!!! as always, many thanks sir

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

    Thanks man, you and your discord channel are very helpful ❤💝

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

    as always perfect video by Stein :)

  • @SpaciX
    @SpaciX Год назад +1

    Hello ) Can you show please how to upload images by websockets ))

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

      Hey, maybe in my next upcoming series 😁

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

    Great content as always.
    1000 thanks Stein.

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

    Hey, you helped me keep my job, thanks a lot!!

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

    Thanks a lot, Bro! Awesome tutorial.

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

    You made it look so easy mate :)

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

    awesome
    Finally a chat app.
    Thank You so much

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

      :-)
      An even better will come as well. I'm working on a simple Slack clone using Django and Vue. It just takes a bit of time :P

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

      @@CodeWithStein Really. I cant wait for that. Though I'm completing the Invoice tutorial now. But when you'll upload the slack clone I'll hand on it.

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

      It will probably take a while, but it will definitely come sometime :-) Great Sazid :-D

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

      @@CodeWithStein waiting for such a wonderful tutorial series.

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

    Thanks, it's really awesome!

  • @TS-ue9he
    @TS-ue9he 3 года назад

    nice, thanks for this tutorial, congrats!

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

    Learning a lot.. thanks for the tutorial... really appreciate... ✨✨✨

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

    It was really useful! thanks!

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

    Thanks for video Stein🤩, but I think real world applications will be more useful 🤗🤗🤗

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

    Great video thank you!

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

    you are a magician

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

    Great video!!!

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

    Wow really nice tutorials
    Thanks

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

    awesome as always :-)

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

      Thanks :-D I hope you enjoy it :-D

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

    Thanks for very helpful 😀

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

    Thanks for ur works to beginners

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

      You're welcome :-D

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

      Can we make Android app from django web??

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

      Yes and no. I guess there are some sort of webview you can use to just show the website. But I'm not sure if Google will allow you to publish it though..

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

    thanks for the tut! superb content, i was wondering how can i do this chat, but more as a group chat (live chat) with several users, being those users registered with django auth and not from the front-end? thanks in advance

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

      Thanks 😁 I’m working on a longer and more advanced tutorial where I will do all of those things. So just wait 👍🏻

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

      @@CodeWithStein it would be awesome as well to have the online usernames in a specific room next to the chat! Just dropping some ideas, thanks again for your content!

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

      Thanks for the tip 👍🏻 I’m working on a new series where I will build a much more conplicated chat. I think you will like that 😉

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

    Hi Stein.
    Thank you, nice tutorial.
    I navigated to GitHub page of this project. Maybe you did not notice, but there is no 'requirements.txt' (or 'pyproject.toml') for dependencies. I also navigated to other chat project page, and there is also no requirements file.
    It would be good to have it committed as well. It will be helpful.
    Regards.

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

      Hey, Thanks for the feedback 👍🏻 i will try to remember to do that ☺️

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

    though I suffer with installation of docker in windows...but the tutorial was great !

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

      Okay :/ I have no experience with Windows (at least not for many years). But thanks :-)

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

      Try memurai

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

    thank you so much

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

    i really appreciate your work, but lots of people are saying that django is becoming obsolete, some company / organizations are moving their backend from django, what do you think?

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

      Thanks :-D
      Django will not be obsolete for a very long time. My experience is that it's growing. I think I have seen graphs pointing up somewhere. It will take many years for Django to be obsolete, so there is no reason not to learn it. All languages/frameworks will be obsolete sometimes anyway ;-)

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

    Thanks

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

    This chat apps will for two user s or multiple users

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

      Hey, you can use it for both 👍🏻

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

    Thanks Sir😆

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

    Wow! But is ti scalable in prodution? fox example 10k user chatting par day

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

      I haven't tried this with many people, but there are probably a few things that needs to be changed in order to use this in production. First of all, replace sqlite3 with postgresql or mysql :-)

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

    Thanks for tutorial but is there a way to build this app without docker

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

      Thank you :-) Sure, you can install Redis on your computer instead of on Docker. But Docker makes it much easier though. I don't have a guide for this, but I don't think it will be too hard...

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

    Can u tell, how can we use only one room for all, means like public chat

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

      Hi! This app built in this tutorial is a public chat. There are no auth, invitatations or similar :-)

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

    Hi! I noticed that the messages you write in room1 will still show up in room2 but if you refresh room2, the messages form room1 will disappear

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

      Hmm, that's weird. It doesn't happen when I go from room to room :S

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

    can you please explain to me what's the procedure of deploying this to the cloud? I have no clear idea to deploying with radis sever

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

      Hi!
      It depends on what service you want to deploy it to. I don't have any guide where this is show (just the django part).

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

      @@CodeWithStein thanks buddy 👍🏻

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

    I am getting error while installing redis ... it gives this error (
    Building wheel for hiredis (setup.py) ... error
    error: subprocess-exited-with-error ,
    Running setup.py install for hiredis ... error
    error: subprocess-exited-with-error
    × Running setup.py install for hiredis did not run successfully.
    │ exit code: 1
    ╰─> [19 lines of output] )
    How can I solve it. Need help.

    • @CodeWithStein
      @CodeWithStein  Год назад +1

      Hey, I haven’t seen that error before :/ are you using Windows?

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

      @@CodeWithStein yes

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

      Okay, I haven’t any suggestions :/ I have no experience with Windows :/

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

    I have got error on all tutorials I have taken that has Channels, not sure if this one will give same error as all the other tutorials I have taken.

    • @CodeWithStein
      @CodeWithStein  Год назад +1

      Hey, what is the error?

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

      @@CodeWithStein I have found a tutorial now that never got the error by using Daphne and now I'm having issues with Docker instead.
      I do: *docker run -p 6379:6379 -d redis:5*
      I get: *docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.*

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

      @@CodeWithStein I had to open the Docker app, if I close the Docker app it is not working.

    • @CodeWithStein
      @CodeWithStein  Год назад +1

      Ah i see, yes that needs to be running ☺️

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

    Can u make a private chat application, like one to one chat

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

      I'm already working on this as part of my premium course here:
      codewithstein.com/courses/build-a-slack-clone-using-django-and-vue/
      :-)

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

    The command docker run -p 6379:6379 -d redis:5 not working, what should I do?

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

      Hi, what error are you getting?

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

      @@CodeWithStein docker is not internal or external
      command, executable program, or batch file.

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

      Hmm, never seen that error :/ is this in Windows? Is docker running? I don’t have too much experience with docker :s

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

      @@CodeWithStein Yes, I use Window. The docker need to download? It's command " docker run -p 6379:6379 -d redis:5" just not working, console return an error that this command does not exist as "docker"((

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

      Yes, you need to download it first 👍🏻 I have no experience with Windows, but I think it’s a simple process ☺️

  • @arf_atelier1819
    @arf_atelier1819 6 месяцев назад +1

    Bro can it work on two laptop

    • @CodeWithStein
      @CodeWithStein  6 месяцев назад

      Yes it can. Over the internet as well 😉

    • @arf_atelier1819
      @arf_atelier1819 6 месяцев назад

      Bro then can you integrate a video call as well...plz 🥺

    • @arf_atelier1819
      @arf_atelier1819 6 месяцев назад

      I'm doing a sign language project..so i need this feature

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

    And is it possible to make so that the user name I specified at registration and already used it, how to make it?

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

      Of course it is! Anything is possible :-D
      It's too much for me to explain here, but if you wait a while, a new tutorial series on the same subject will be published here. A simple slack clone with teams and channels :-D

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

      @@CodeWithStein Sorry, I already worked with web sockets for comments, there I took on a foreign key user model, here I need to do the same? And to remove json for a username?

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

    Hey what is the command you wrote at 9:53 , (for windows)

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

      my server is not running. "You have not set ASGI_APPLICATION, which is needed to run the server." getting this error.

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

      Hi, I don't have Windows so I'm not sure what the command will be there :/
      Then you just need to add "ASGI_APPLICATION" to your settings.py and point it to the correct file like I do in the video :-)

  • @berkefekeskin9172
    @berkefekeskin9172 6 месяцев назад +1

    For the new comers, if you use channels 3.0.5 or later versions. Be carefull, because ASGI server wont start at django's DEBUG MODE!!!!

    • @CodeWithStein
      @CodeWithStein  6 месяцев назад

      I have s newer chat tutorial where i use channels 4 btw 👍🏻

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

    How do I implement this without using docker?

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

      Hi!
      Use this in your settings.py:
      CHANNEL_LAYERS = {
      'default': {
      'BACKEND': 'channels.layers.InMemoryChannelLayer',
      },
      }

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

    WebSocket is already in CLOSING or CLOSED state

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

      I think it's an issue with Chrome. Try googling the error and you'll probably find the solution :-)

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

      @@CodeWithStein ok

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

      @@CodeWithStein when send a message then in terminal show disconnected .

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

    Any method to send files also?

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

      I won't implement it here, but maybe in the more complex tutorial I'm working on. A simple Slack clone with DRF and Django ;-)

  • @aditya.01020
    @aditya.01020 3 года назад +1

    Great Tutorial
    Why everything on mac is so clean,
    Yes, I am on windows and it is very buggy and ugly.

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

      Thank you ☺️ because Mac is the best and Windows isn’t 😝

    • @aditya.01020
      @aditya.01020 3 года назад

      @@CodeWithStein Wow that gone straight up through my heart 😞

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

      Haha, sorry 😛

    • @aditya.01020
      @aditya.01020 3 года назад

      @@CodeWithStein NVM, my workspace is cleaner than most other people and I love it.

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

    How write restapi for this

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

      Not sure what a restapi has to do with a real time chat?

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

    Hiii sir plzz help me
    Can you plzz make a tutorial for "online diagnostic lab reporting system" i hqve to submit it in next one week plzz make it

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

      Sure, just let me clear the calendar. Since this will require me to work 24/7 (I guess) = 168 hours * $100 = $16800. Just send it to my PayPal ;-)

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

      @@CodeWithStein sure i will pay. Plzz upload the tutorial

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

      Plzz do the project and upload it as soon as possible

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

      @@CodeWithStein sir i want this as my college project i m btech student.
      I have to submit it as my major project

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

      I don't know if you didn't understand that I was just being sarcastic or what, but there is no way that I could do this in such a short amount of time. And why should I use MY time to do YOUR work?
      If you're a tech student and this is your major, then you should build it your self :P

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

    How can i run in my vs code

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

      Hey, hit cmd+r I think 😉

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

      @@CodeWithStein sir this code , after getting source code when i try to run thhis code the web is getting crash

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

      @@CodeWithStein sir pls help me tomorrow i have an internship project submission and i use this code..pls help 😔🙏

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

      Hey, what is the error? Are there anything in the console?

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

      @@CodeWithStein no..there's nothing eror but i dont how to execute this program in my pc