我如何在Django和Windows中编写Redis通道层

问题描述 投票:0回答:1

我的settings.py中有此代码,但是在django和Windows中似乎不起作用,关于如何更正此代码的任何想法?我在设置中使用了Redis服务器后端,使我的consumers.py正常运行]

async def websocket_receive(self, event):
    print('receive', event)
    front_text = event.get('text', None)
    if front_text is not None:
        loaded_dict_data = json.loads(front_text)
        msg = loaded_dict_data.get('message')
        user = self.scope['user']
        username = 'default'
        if user.is_authenticated:
            username = user.username
        myResponse = {
            'message': msg,
            'username': username
        }
        await self.create_chat_message(user, msg)
        await self.channel_layer.group_send(
            self.chat_room,
            {
                "type": "chat_message",
                "text": json.dumps(myResponse)
            }
        )

async def chat_message(self, event):
    print('message', event)
    await self.send({
        "type": "websocket.send",
        "text": event["text"]
    })

这是我的settings.py

CHANNEL_LAYERS = {
    'default':
        { 'BACKEND': 'channels_redis.core.RedisChannelLayer',
          'CONFIG':{
              "hosts": [('127.0.0.1', 6379)],
          },
        },
}

我尝试过的

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
        },
    },
}
django redis
1个回答
0
投票

您正在StudentProfile子句中选择.values的外键,而不是名称字段。要解决此问题,只需添加__Firstname

students = studentsEnrolledSubjectsGrade.objects.filter(Teacher=teacher).filter(grading_Period=period).filter(
 Subjects=subject).filter(Grading_Categories=category).filter(GradeLevel=grade).order_by(
        'Students_Enrollment_Records', 'Date'
).values('Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Firstname', 'Date', 'Grade').distinct()
© www.soinside.com 2019 - 2024. All rights reserved.