0

I'm really confused about that. I want to make a user to user chat app on my project with Django and React. I've tried create a model and fetch messages with Rest Framework API. But that's not what i need.

I need to live chat between just two users. When a user send a message to me i want to display that instantly (without click anywhere) like Whatsapp. When i try this with DRF i can get messages and save them inside to useState. But i must to refresh page for display new messages. I don't want to this. I don't want to refresh to page.

How can i do that? I saw Django Channel but i don't know can i use this for just between two user's private messaging. Also i don't know how to set this on React JS.

Can anyone help me? I just need your opinions. I can try your opinion. You don't have to write code for me.

1 Answers1

0

You have to use web sockets if you want to display data live. So, for example, someone sent a message to the server and the server instantly send it to the socket target.

Here is the simple chat application wrote with socketio, you just have to follow it step by step https://socket.io/get-started/chat

programmer
  • 550
  • 2
  • 4
  • 25
  • Hey again. I made a live chat with your opinon. That’s so useful for me and it’s working. But i want to store all messages. How can i do that. May you give me an opinion again please? –  Jul 01 '21 at 21:15
  • As same as before it depends... But lest say you have to use the database, you can use MongoDB which is a non-relative database, and some relative databases like PostgreSQL. What I can recommend to you is look at this discussion -> https://stackoverflow.com/questions/7063051/best-way-to-store-chat-messages-in-a-database – programmer Jul 02 '21 at 22:06