6

i am using django channels in my project using using official django channels v2, my simple channels app is completed and working fine if run python manage.py runserver but i want to run django channels in different port so i am now using daphne
using daphne my_project.asgi:application --port 8001 it working fine in 8001 port

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)

and i also run python manage.py runserver in another terminal parallely working fine. now my both channels in 8001 and django in 8000 port working correctly but my runserver command running ASGI/Channels instead of wsgi development server,

Starting ASGI/Channels version 2.2.0 development server at http://127.0.0.1:8000/

instead of

Starting development server at http://127.0.0.1:8000/

settings.py

ASGI_APPLICATION = 'my_project.routing.application'

WSGI_APPLICATION = 'my_project.wsgi.application'

if i debug any function in views.py request, it is ASGI request instead of django wsgi request

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()

my question is:

  1. how to get django request instead of ASGI request in our normal function view request(like def index(request)) or if we install django channels every request become ASGI request?
  2. what is the use of the python mange.py runworker command
4

1 回答 1

2

就像你可以在这里阅读:https ://asgi.readthedocs.io/en/latest/

ASGI(异步服务器网关接口)是 WSGI 的精神继承者,旨在提供支持异步的 Python Web 服务器、框架和应用程序之间的标准接口。

在 WSGI 为同步 Python 应用程序提供标准的地方,ASGI 为异步和同步应用程序提供了一个标准,具有 WSGI 向后兼容实现以及多个服务器和应用程序框架。

所以你的问题 nr 1 的答案是:Yes, all requests will be ASGI

问题 nr 2 - 这是运行多个工作人员以异步方式处理您的频道请求的命令https://channels.readthedocs.io/en/1.x/deploying.html#run-worker-servers

于 2019-09-05T09:39:15.980 回答