Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate asgi.py for existent project?

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?

like image 811
Xhark Avatar asked Feb 04 '20 09:02

Xhark


People also ask

What is ASGI py file in Django?

ASGI (Asynchronous Server Gateway Interface) provides an interface between async Python web servers and applications while it supports all the features provided by WSGI.

Should I use WSGI or ASGI?

ASGI is a spiritual successor to WSGI, the long-standing Python standard for compatibility between web servers, frameworks, and applications. WSGI succeeded in allowing much more freedom and innovation in the Python web space, and ASGI's goal is to continue this onward into the land of asynchronous Python.

Is Django WSGI or ASGI?

As well as WSGI, Django also supports deploying on ASGI, the emerging Python standard for asynchronous web servers and applications.


1 Answers

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()
like image 139
Alper Avatar answered Oct 07 '22 11:10

Alper