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
Woohooo... Finally.
Been waiting for this!
Yeah :-D
amazing video, still useful in 2023
Thanks 😁
What an excellent tutorial!!!! Can't wait for the new advanced version to drop soon!!
Thanks :-D Sounds great, it will probably be a premium course though ;-)
Excellent, a few months ago asked for this tutorial finally you are started, thank you so much for the tutorial
You're welcome :-) Thanks for always being a loyal subscriber :-D
Thanks a lot, Bro! Awesome tutorial. its my first time to see you on RUclips, you are great
Nice, Thanks 😁
Another excellent tutorial regarding how to build a simple realtime chat application using Django, Web sockets, Channels and Redis.
Thank you Dale :-D
are deploying on server ? not working /ws = /, how to solutions ?
Yes, you can deploy this. I dont understand what you are asking for? 🤷🏼♂️
It wasn't me that asked that question.
Thanks
I know Dale ☺️ the commenting system here just isn’t the best :/
I have been looking for an up-to-date tutorial on this. Thanks
Perfect :-D
Greetings, Stein is at it again, smiles, awesome!!!! as always, many thanks sir
Thanks :-D And yes I am :-)
Thanks man, you and your discord channel are very helpful ❤💝
Thanks :-D
as always perfect video by Stein :)
Thanks 😁😁
Hello ) Can you show please how to upload images by websockets ))
Hey, maybe in my next upcoming series 😁
Great content as always.
1000 thanks Stein.
Thank you so much :-D
Hey, you helped me keep my job, thanks a lot!!
Cool 😁😁😁
Thanks a lot, Bro! Awesome tutorial.
Thanks for the feedback :-D
You made it look so easy mate :)
Thanks :-D
awesome
Finally a chat app.
Thank You so much
:-)
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
@@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.
It will probably take a while, but it will definitely come sometime :-) Great Sazid :-D
@@CodeWithStein waiting for such a wonderful tutorial series.
Thanks, it's really awesome!
Thank you 😁😁
nice, thanks for this tutorial, congrats!
Thanks for the feedback 😁
Learning a lot.. thanks for the tutorial... really appreciate... ✨✨✨
Thanks man 😁😁
It was really useful! thanks!
Thank you so much :-D
Thanks for video Stein🤩, but I think real world applications will be more useful 🤗🤗🤗
It will come 😉😉😉
@@CodeWithStein thanks 😊
Great video thank you!
You're welcome :-D
you are a magician
I know 😁😁
Great video!!!
Thank you so much :-D
Wow really nice tutorials
Thanks
Thanks :-D
awesome as always :-)
Thanks :-D I hope you enjoy it :-D
Thanks for very helpful 😀
Thanks :-D
Thanks for ur works to beginners
You're welcome :-D
Can we make Android app from django web??
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..
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
Thanks 😁 I’m working on a longer and more advanced tutorial where I will do all of those things. So just wait 👍🏻
@@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!
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 😉
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.
Hey, Thanks for the feedback 👍🏻 i will try to remember to do that ☺️
though I suffer with installation of docker in windows...but the tutorial was great !
Okay :/ I have no experience with Windows (at least not for many years). But thanks :-)
Try memurai
thank you so much
You’re welcome 😁
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?
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 ;-)
Thanks
You’re welcome 😁
This chat apps will for two user s or multiple users
Hey, you can use it for both 👍🏻
Thanks Sir😆
You're welcome :-D
Wow! But is ti scalable in prodution? fox example 10k user chatting par day
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 :-)
Thanks for tutorial but is there a way to build this app without docker
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...
Can u tell, how can we use only one room for all, means like public chat
Hi! This app built in this tutorial is a public chat. There are no auth, invitatations or similar :-)
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
Hmm, that's weird. It doesn't happen when I go from room to room :S
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
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).
@@CodeWithStein thanks buddy 👍🏻
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.
Hey, I haven’t seen that error before :/ are you using Windows?
@@CodeWithStein yes
Okay, I haven’t any suggestions :/ I have no experience with Windows :/
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.
Hey, what is the error?
@@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?.*
@@CodeWithStein I had to open the Docker app, if I close the Docker app it is not working.
Ah i see, yes that needs to be running ☺️
Can u make a private chat application, like one to one chat
I'm already working on this as part of my premium course here:
codewithstein.com/courses/build-a-slack-clone-using-django-and-vue/
:-)
The command docker run -p 6379:6379 -d redis:5 not working, what should I do?
Hi, what error are you getting?
@@CodeWithStein docker is not internal or external
command, executable program, or batch file.
Hmm, never seen that error :/ is this in Windows? Is docker running? I don’t have too much experience with docker :s
@@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"((
Yes, you need to download it first 👍🏻 I have no experience with Windows, but I think it’s a simple process ☺️
Bro can it work on two laptop
Yes it can. Over the internet as well 😉
Bro then can you integrate a video call as well...plz 🥺
I'm doing a sign language project..so i need this feature
And is it possible to make so that the user name I specified at registration and already used it, how to make it?
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
@@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?
Hey what is the command you wrote at 9:53 , (for windows)
my server is not running. "You have not set ASGI_APPLICATION, which is needed to run the server." getting this error.
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 :-)
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!!!!
I have s newer chat tutorial where i use channels 4 btw 👍🏻
How do I implement this without using docker?
Hi!
Use this in your settings.py:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer',
},
}
WebSocket is already in CLOSING or CLOSED state
I think it's an issue with Chrome. Try googling the error and you'll probably find the solution :-)
@@CodeWithStein ok
@@CodeWithStein when send a message then in terminal show disconnected .
Any method to send files also?
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 ;-)
Great Tutorial
Why everything on mac is so clean,
Yes, I am on windows and it is very buggy and ugly.
Thank you ☺️ because Mac is the best and Windows isn’t 😝
@@CodeWithStein Wow that gone straight up through my heart 😞
Haha, sorry 😛
@@CodeWithStein NVM, my workspace is cleaner than most other people and I love it.
How write restapi for this
Not sure what a restapi has to do with a real time chat?
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
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 ;-)
@@CodeWithStein sure i will pay. Plzz upload the tutorial
Plzz do the project and upload it as soon as possible
@@CodeWithStein sir i want this as my college project i m btech student.
I have to submit it as my major project
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
How can i run in my vs code
Hey, hit cmd+r I think 😉
@@CodeWithStein sir this code , after getting source code when i try to run thhis code the web is getting crash
@@CodeWithStein sir pls help me tomorrow i have an internship project submission and i use this code..pls help 😔🙏
Hey, what is the error? Are there anything in the console?
@@CodeWithStein no..there's nothing eror but i dont how to execute this program in my pc