我正在使用官方django channels v2
在我的项目中使用django频道,我的简单频道应用已完成并且如果运行python manage.py runserver
可以正常工作
但
我想在其他端口中运行django通道,所以现在使用daphne
使用daphne
my_project.asgi:application --port 8001
可以在8001端口上正常工作
INFO Starting server at tcp:port=8001:interface=127.0.0.1
INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras)
,并且我还在另一个终端并行运行python manage.py runserver
正常工作。现在我在8001
中的两个通道和在8000
端口中的django都可以正常工作,但是我的runserver命令运行的是ASGI / Channels而不是wsgi开发服务器,
Starting ASGI/Channels version 2.2.0 development server at http://127.0.0.1:8000/
代替
Starting development server at http://127.0.0.1:8000/
settings.py
ASGI_APPLICATION = 'my_project.routing.application'
WSGI_APPLICATION = 'my_project.wsgi.application'
如果我在views.py
请求中调试了任何功能,则它是ASGI请求而不是django wsgi请求
asgi.py
import os
import django
from channels.routing import get_default_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
django.setup()
application = get_default_application()
我的问题是:
def index(request)
)中获取django请求而不是ASGI请求,或者如果我们安装django通道,则每个请求都将成为ASGI请求?答案 0 :(得分:1)
就像您可以在这里阅读:https://asgi.readthedocs.io/en/latest/
ASGI(异步服务器网关接口)是继任者 WSGI,旨在在两者之间提供标准接口 具有异步功能的Python Web服务器,框架和应用程序。
WSGI为同步Python应用程序提供了标准,ASGI 通过WSGI为异步和同步应用程序提供一个 向后兼容实现和多个服务器以及 应用程序框架。
因此,您对第1个问题的答案是:Yes, all requests will be ASGI
。
问题2-这是运行多个工作程序以异步方式https://channels.readthedocs.io/en/1.x/deploying.html#run-worker-servers处理您的频道请求的命令