问题描述
我正在使用Django开发应用程序,最初是使用WSGI环境将其部署在Google Cloud Platform上,现在我已经在应用程序和使用的通道中添加了一些功能,由于这些原因,我不得不从WSGI转换为ASGI,但是使用ASGI环境时在部署到Google Cloud Platform时出现错误
I am developing an app using Django,I have deployed it on Google Cloud Platform initially using WSGI environment,now I have made addition in app and used channels due to which I have to shift from WSGI to ASGI, but I am getting errors while deploying to Google Cloud Platform when I use ASGI environment
我收到错误消息: respiter = self.wsgi(environ,resp.start_response)TypeError:__call __()接受2个位置参数,但给出了3个位置
当我想使用ASGI环境时,我评论了WSGI文件的所有内容,这是我的相关代码:
I commented the all content of WSGI file when I want to use ASGI environmnet,here's me related code:
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应用程序的方式是否正确?
How can I run ASGI environment? If I missed something in showing my code I can also show that,I can't get what the problem is,Is my way of deploying ASGI app is correct?
推荐答案
App Engine Standard当前不支持ASGI.
App Engine Standard currently does not support ASGI.
要与ASGI一起使用,您应该使用App Engine Flexible,您可以在其中进一步调整环境.
To work with ASGI you should use App Engine Flexible, where you can tweak the environment much further.
然后,您可能会在GAE flex文档中找到有关使用WebSocket创建持久连接.
Then, you might find useful the guide in the GAE flex documentation about Creating Persistent Connections with WebSockets.
这篇关于部署应用Django Rest时在运行ASGI环境中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!