[英]How to display messages in a chat application in Django
I am building a chat application in Django.我正在 Django 中构建一个聊天应用程序。 But I am confused about how to show messages as soon as the person on the other side sends a message.
但是我对如何在对方发送消息后立即显示消息感到困惑。 At present, I have to reload the page to view the messages.
目前,我必须重新加载页面才能查看消息。 I thought of refreshing the page automatically for 3-5 seconds.
我想自动刷新页面 3-5 秒。 Is there any way to display messages as soon as the other person sends a message
有什么方法可以在对方发消息后立即显示消息
You need to use websockets to obtain such type of applications.您需要使用 websockets 来获取此类应用程序。 Web sockets maintain a link with your server and when ever there is a change in server the user gets notified automatically without refreshing.
Web sockets 与您的服务器保持链接,当服务器发生变化时,用户会自动收到通知而无需刷新。
You should use websockets to accomplish this.您应该使用 websockets 来完成此操作。 The library to go is django channels ( https://channels.readthedocs.io/en/latest/ ) and in their example they also build a small chat application.
go 的库是 django 频道( https://channels.readthedocs.io/en/latest/ ),在他们的示例中,他们还构建了一个小型聊天应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.