[Answered ]-Daphne ModuleNotFoundError: No module named 'app_name'

1๐Ÿ‘

โœ…

I had to append the folder where all my apps lie to the PYTHONPATH environment variable like so:
PYTHONPATH="${PYTHONPATH}:/project_name/project_name"

๐Ÿ‘คcalen

0๐Ÿ‘

just like this. add a environment path to asgi.py

    from channels.auth import AuthMiddlewareStack
    import sys
    sys.path.append('your-project-abspath')
    import chat.routing
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'env.settings')

    application = ProtocolTypeRouter(
    {
        "http":get_asgi_application(),
        "websocket": AuthMiddlewareStack(
            URLRouter(
                chat.routing.websocket_urlpatterns
            )
        ),
    }
)
๐Ÿ‘คLarge hare

0๐Ÿ‘

import os

import django
django.setup()

from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application

from notification.routing import websocket_urlpatterns

from notification.utils.websocket_auth import WebSocketAuthMiddleware

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

application = ProtocolTypeRouter(
    {
        "http": get_asgi_application(),
        "websocket": WebSocketAuthMiddleware(
            URLRouter(websocket_urlpatterns)
        ),
    }
)

In my case django setup fixed the problem.

just put django setup in asgi file.

๐Ÿ‘คaoulaa

Leave a comment