【发布时间】:2022-01-17 04:54:46
【问题描述】:
我正在使用 python version==3.8.10 和 Django==2.2 和 channels==3.0.4 。我收到错误
从频道导入频道 ImportError:无法从“频道”(/home/kritik/py38_djanngo2.2_new/lib/python3.8/site-packages/channels/init.py)导入名称“频道”
这就是我的代码的样子。这是我使用 channels=1.1.2 和 python 2.7 和 Django=1.11.13 时的旧代码。现在当我升级时出现错误我需要更新代码吗?如果是,那我需要更新什么?
from channels import Channel
class TestWebSocket(APIView):
def post(self, format=None):
try:
REPLY_CHANNEL = self.request.data['request_channel']
# job = Job(
# name= new_data[0]['change_type'],
# status="COS initiation has started. Please be patient.",
# )
# job.save()
# Tell client task has been started
Channel(REPLY_CHANNEL).send({
"text": json.dumps({
"action": "started",
})
})
return Response({"Success": "Sucess"}, status=status.HTTP_200_OK)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)
谁能帮我解决这个问题?
【问题讨论】:
标签: python-3.x django django-rest-framework django-channels