django - 部署应用程序 Django Rest 时运行 ASGI 环境的问题

标签 django google-cloud-platform django-channels django-wsgi asgi

我正在使用 Django 开发一个应用程序,我最初使用 WSGI 环境将它部署在 Google Cloud Platform 上,现在我在应用程序中添加了内容并使用了 channel ,因此我必须从 WSGI 转移到 ASGI,但我越来越使用 ASGI 环境部署到 Google Cloud Platform 时出错

我收到错误:respiter = self.wsgi(environ, resp.start_response) TypeError: __call__() takes 2 positional arguments but 3 were given

我在使用ASGI environmnet的时候注释掉了WSGI文件的所有内容,下面是我的相关代码:

ASGI 文件:

import os
import django
from channels.routing import get_default_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')
django.setup()
application = get_default_application()

WSGI 文件(我已评论):

"""
WSGI config for Frames project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/


import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Frames.settings')

application = get_wsgi_application()"""

ma​​in.py:

from Frames.asgi import application
app = application

Settings.py(主要变化,我已经从settings.py中删除了所有与WSGI相关的内容)


ASGI_APPLICATION = "Frames.routing.application"

CHANNEL_LAYERS={
    "default":{
      "BACKEND": "channels_redis.core.RedisChannelLayer",
      "CONFIG": {
                "hosts": [("localhost", 6379)],
            },
    },
}

如何运行ASGI环境?如果我在展示我的代码时遗漏了什么,我也可以展示,我无法理解问题所在,我部署 ASGI 应用程序的方式是否正确?

最佳答案

App Engine Standard 目前不支持 ASGI。

要使用 ASGI,您应该使用 App Engine Flexible,您可以在其中进一步调整环境。

然后,您可能会发现有关 Creating Persistent Connections with WebSockets 的 GAE flex 文档中的指南很有用。 .

关于django - 部署应用程序 Django Rest 时运行 ASGI 环境的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59527805/

相关文章:

scala - Apache 弗林克 : How to sink stream to Google Cloud Storage File System

python - 无法在 Django 1.11.13 上安装 Django-Channel

django websockets 无法在 channel 上发送消息

python - Heroku 上的全新部署失败,出现 "use --allow-unverified PIL to allow"

python - 动态模型 Django 2019

python - 如何删除模板中 django URL 中的尾部斜线?

kubernetes - 从 GKE 集群中删除节点后,GEK 不会自动启动新节点

google-cloud-platform - 通过 ESPv2 : Problem with timeout 的谷歌云功能 + 端点

python - 如何在 django 的两边设置多对多字段空白=真

python - 为什么Django Channels Daphne不能使用多线程并发处理请求?