How to generate asgi.py for existent project?
Asked Answered
P

2

8

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?

Province answered 4/2, 2020 at 9:23 Comment(1)
Have you read this? And you don't need to use Django 3.0 to use channels by the way.Bouley
N
5

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()
Nett answered 26/5, 2020 at 22:6 Comment(1)
It is worth mentioning that the module django.core.asgi does not exist in Django 2.2, the version mentioned in the question.Engender
E
1

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()
Engender answered 11/3, 2021 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.