Daphne ModulenotFoundError:No模块名为' app_name'
当我运行Daphne -B 0.0.0.0 -p 8000 -Access -log = daphne.log config.asgi:应用程序
我获得Daphne ModulenotFoundError:no模块名为“ App_name”
,
但是当我运行Python3 Manage.py Runserver
时,它正常工作吗? 当我从installed_apps
中删除app_1
时,它将向我显示modulenotfounderror:no模块名为'app_2'
这是我的文件夹结构:
project_name
│ __init__.py
│ manage.py
│
└───config
│ │ __init__.py
│ │ asgi.py
│ │ celery.py
│ │ urls.py
│ │ wsgi.py
│ │
│ └───settings
│ │
│ │ __init__.py
│ │ base.py
│ │ dev.py
│ │ prod.py
│
│
└───project_name
│ │ __init__.py
│ │
│ └───app_1
│ └───app_2
│ └───app_3
│
└───media
│
└───static
asgi。 PY
:
from django.core.asgi import get_asgi_application
django_asgi_app = get_asgi_application()
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from chat import routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')
application = ProtocolTypeRouter({
'http': django_asgi_app,
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})
When I run daphne -b 0.0.0.0 -p 8000 --access-log=daphne.log config.asgi:application
I get Daphne ModuleNotFoundError: No module named 'app_name'
But when I run python3 manage.py runserver
it works normally?
When I remove app_1
from INSTALLED_APPS
it will show me ModuleNotFoundError: No module named 'app_2'
This is my folder structure:
project_name
│ __init__.py
│ manage.py
│
└───config
│ │ __init__.py
│ │ asgi.py
│ │ celery.py
│ │ urls.py
│ │ wsgi.py
│ │
│ └───settings
│ │
│ │ __init__.py
│ │ base.py
│ │ dev.py
│ │ prod.py
│
│
└───project_name
│ │ __init__.py
│ │
│ └───app_1
│ └───app_2
│ └───app_3
│
└───media
│
└───static
asgi.py
:
from django.core.asgi import get_asgi_application
django_asgi_app = get_asgi_application()
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from chat import routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')
application = ProtocolTypeRouter({
'http': django_asgi_app,
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不得不将所有应用都位于PythonPath环境变量的文件夹附加到这样的文件夹:
pythonpath =“ $ {pythonpath}:/project_name/project_name”
I had to append the folder where all my apps lie to the PYTHONPATH environment variable like so:
PYTHONPATH="${PYTHONPATH}:/project_name/project_name"
就像这样。 为Asgi.py添加环境路径
just like this. add a environment path to asgi.py
在我的情况下,django设置解决了问题。
只需将Django设置放在ASGI文件中即可。
In my case django setup fixed the problem.
just put django setup in asgi file.