I have an existent django project in 2.2, but now i would like to start using channels, so I have to change to 3.0 and asgi instead of wsgi.
How can I generate the asgi.py that I need to run the app?
I have an existent django project in 2.2, but now i would like to start using channels, so I have to change to 3.0 and asgi instead of wsgi.
How can I generate the asgi.py that I need to run the app?
Django has a template file here that it uses to generate the asgi.py
.
Jus copy paste this next to your wsgi.py
:
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')
application = get_asgi_application()
django.core.asgi
does not exist in Django 2.2, the version mentioned in the question. –
Engender For Django==2.2
, I found the solution in this link. For the asgi.py
file, the content would be:
"""
ASGI entrypoint. Configures Django and then runs the application
defined in the ASGI_APPLICATION setting.
"""
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
django.setup()
application = get_default_application()
© 2022 - 2024 — McMap. All rights reserved.