django.core.exceptions.ImproperlyConfigured:无法导入ASGI_APPLICATION模块'snp. routing'

wydwbb8l  于 2023-01-10  发布在  Go
关注(0)|答案(2)|浏览(236)
ASGI_APPLICATION = 'snp.routing.application'

routing.py:

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter

import chat.routing

application = ProtocolTypeRouter ({
    'websocket': AuthMiddlewareStack(
        URLRouter (
            chat.routing.websocket_urlpatterns
        )
    )
})

我在导入ASGI_APPLICATION时遇到此错误,如何修复它
引发配置不正确(“无法导入ASGI_APPLICATION模块%r”% path)django.core.异常。配置不正确:无法导入ASGI_APPLICATION模块'snp.routing'

sirbozc5

sirbozc51#

from django.core.asgi import get_asgi_application

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator

import appname.routing

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

application = ProtocolTypeRouter({
    'http': get_asgi_application(),
    'websocket': AllowedHostsOriginValidator(
        AuthMiddlewareStack((
            URLRouter(
                appname.routing.webscoket_urlpatterns
            )
        ))
    )
})

试试这个:)

ckx4rj1h

ckx4rj1h2#

在我的情况下,我只是没有安装通道库。

pip install channels

试试这个

相关问题