简体   繁体   English

如何在 Django 的聊天应用程序中显示消息

[英]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.

相关问题 在多频道聊天应用程序中,如何显示仅与特定聊天频道有关的消息? - In a multichannel chat application how can I display messages pertaining only to a specific chat channel? javascript 聊天显示消息 - javascript chat display messages 获取聊天记录中的消息以显示在 Messenger Pubnub 中 - Getting messages in chat history to display in messenger Pubnub 在聊天应用程序中显示在线用户 - Display Online users in a chat application 如何在 React 中持久化聊天消息? - How to persist chat messages in React? 如何显示从数据库接收的消息数组,用于聊天室 - How to display an array of messages being received from database, for a chat-room 如何使键入的聊天消息显示在屏幕上? (socket.io 和 node.js) - How to make typed chat messages display on the screen? (socket.io and node.js) NodeJs、Express、Socket.io 聊天应用程序,如何为发送方和接收方发出两种不同类型的消息? - NodeJs, Express, Socket.io chat application, how to emit two different types of messages for sender and receivers? 如何在 React 中显示来自 django-rest-framework 的错误消息 - How to display error messages from django-rest-framework in React 如何使用python Django从Ajax显示来自表单的错误消息 - How to display error messages from form with ajax using python django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM