python - 使用 django shell 的 Django channel

标签 python django django-celery django-channels

我目前正在尝试使用 Celery 通过 django channel 发送套接字。然而,我发现了与使用 Django 的 shell 相同的问题,希望有人能启发我。

我已将其设置为在views.py 中,当用户发送 POST 请求时,它将调用

Group("chat").send({'text':'hello'})

然后浏览器会显示一条警报。

但是,当我尝试使用 Django 的 shell 或 Celery 的任务之一执行相同的操作时:

$ python3 manage.py shell
$ from channels import Group
$ Group("chat").send({'text': 'hello'})

它不执行任何操作,甚至不返回错误。

最佳答案

如果您使用内存中 channel 层,那么可能它不支持跨进程通信。因此尝试使用其他 channel 层类型,就可以了.

关于python - 使用 django shell 的 Django channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39114502/

相关文章:

python - 如何在 Python 中创建一系列文本菜单

python - 垂直打印列表字典

python - Django:解压参数列表以在聚合查询中使用

django - 订购 admin.ModelAdmin 对象

django - 你可以在与 Django 不同的容器中运行 Celery 吗?

celery - 启动CeleryBeat时出现Django Celery错误-无法将项目添加到数据库

python - 使用工作流在 github 中对 databricks python 代码进行 flake8 linting

python - Python中的Haversine公式(两个GPS点之间的方位和距离)

django 1.8 教程第 6 部分

django - celery 3.1.5 中的线程