Django不将其重定向到网页
我正在使用内置DLP系统在Django中创建消息传递应用程序。当消息中检测到敏感单词时,我想重定向到网页。但是网页没有被重定向到。它在终端显示,但不在前端。
在consumer.py
async def chat_message(self, event):
message = event['message']
username = event['username']
if (re.findall("yes|Yes", message)):
response = await requests.get('http://127.0.0.1:8000/dlp/')
print('message')
else:
await self.send(text_data=json.dumps({
'message': message,
'username': username
}))
终端中的输出
WebSocket CONNECT /ws/2/ [127.0.0.1:32840]
HTTP GET /dlp/ 200 [0.00, 127.0.0.1:32842]
message
I am creating a messaging application in django with a built-in DLP system. I want to redirect to a web page when a sensitive word is detected in the message. But the webpage is not being redirected to. It is showing in the terminal but not on the front-end.
In consumers.py
async def chat_message(self, event):
message = event['message']
username = event['username']
if (re.findall("yes|Yes", message)):
response = await requests.get('http://127.0.0.1:8000/dlp/')
print('message')
else:
await self.send(text_data=json.dumps({
'message': message,
'username': username
}))
The output in the terminal
WebSocket CONNECT /ws/2/ [127.0.0.1:32840]
HTTP GET /dlp/ 200 [0.00, 127.0.0.1:32842]
message
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,您的后端请求
/dlp
页面,接收响应,并打印字符串'消息'
到控制台。它不会向前端发送任何数据。我认为,最简单的解决方案是将
status
字段添加到您的JSON并在JavaScript中处理。Now your backends requests
/dlp
page, receives the response and prints string'message'
to console. It doesn't send any data to frontend.The most simple solution, I think, will be to add
status
field to your json and handle it in javascript.