【问题标题】:ASGI_APPLICATION not working with Django ChannelsASGI_APPLICATION 不适用于 Django 频道
【发布时间】:2022-11-10 15:28:56
【问题描述】:

我按照频道文档中的教程进行操作,但是当我启动服务器 python3 manage.py runserver 时,它给了我这个:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

当我期望它给我这个时:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 17, 2022 - 00:13:21
Django version 4.1.2, using settings 'config.settings'
Starting ASGI/Channels version 3.0.5 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

设置.py

INSTALLED_APPS = [
    'channels',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ...
]

ASGI_APPLICATION = 'config.asgi.application'

asgi.py

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
})

即使我将ASGI_APPLICATION = 'config.asgi.application 更改为ASGI_APPLICATION = '',它也不会出现任何错误。

【问题讨论】:

    标签: python django django-channels


    【解决方案1】:

    这可能是因为您使用的 Django 和频道版本不兼容 试试看:channels==3.0.4 and django==4.0.0

    【讨论】:

      【解决方案2】:

      使用频道支持的python版本,你会在pypi频道页面找到它

      【讨论】:

        猜你喜欢
        • 2019-04-08
        • 2022-12-15
        • 2021-08-22
        • 1970-01-01
        • 2021-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多