【发布时间】:2020-04-19 00:30:13
【问题描述】:
我正在使用 Django 开发一个应用程序,我最初使用 WSGI 环境将它部署在 Google Cloud Platform 上,现在我已经在应用程序中添加并使用了通道,因此我必须从 WSGI 转移到 ASGI,但我得到了使用 ASGI 环境时部署到 Google Cloud Platform 时出错
我收到错误:respiter = self.wsgi(environ, resp.start_response) TypeError: __call__() 接受 2 个位置参数,但给出了 3 个
当我想使用ASGI环境时,我注释了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()"""
main.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 应用程序的方式是否正确?
【问题讨论】:
-
您的应用程序运行情况如何?你的
entrypoint是什么? -
它自动从我提到的 main.py 文件加载,它调用 ASGI 文件(这是入口点)
-
在您评论了 WSGI 的所有内容后,您仍然收到呼吸器错误吗?或者评论完所有 WSGI 后出现的错误是什么?
-
我得到的唯一呼吸器错误
标签: django google-cloud-platform django-channels django-wsgi asgi