gpt4 book ai didi

django - 如何在 django channel 的 daphne ASGI 一侧运行 wsgi

转载 作者:行者123 更新时间:2023-12-03 19:24:43 25 4
gpt4 key购买 nike

我在我的项目中使用 django channel ,使用官方 django channels v2 ,如果运行 python manage.py runserver,我的简单 channel 应用程序已完成并且可以正常工作

我想在不同的端口运行 django channel ,所以我现在使用 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在另一个终端并行工作正常。现在我的两个 channel 都在 8001和 Django 在 8000端口工作正常,但我的 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/

设置.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()

我的问题是:
  • 如何在我们的普通函数 View 请求(如 def index(request) )中获取 django 请求而不是 ASGI 请求,或者如果我们安装 django channel ,每个请求都成为 ASGI 请求?
  • python mange.py runworker 命令有什么用
  • 最佳答案

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

    ASGI (Asynchronous Server Gateway Interface) is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.

    Where WSGI provided a standard for synchronous Python apps, ASGI provides one for both asynchronous and synchronous apps, with a WSGI backwards-compatibility implementation and multiple servers and application frameworks.



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

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

    关于django - 如何在 django channel 的 daphne ASGI 一侧运行 wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57801016/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com