python - 带有 azure web 应用程序和存储的 Django 频道
问题描述
我一直在尝试使用 Azure Web 应用程序和 azure redis 缓存为我的 django 应用程序设置生产环境。
在我的浏览器中,我在控制台中收到此错误:
(index):157 WebSocket connection to 'wss://<mysite>.azurewebsites.net/ws/chat/hey/' failed: Error during WebSocket handshake: Unexpected response code: 404
在我的 settings.py 中,我尝试了几种不同的设置。我可以一起工作的最后一个
from django.core.cache import cache
cache.set("gg", "1234567")
print(cache.get("gg"))
我可以从 Azure 门户上的 Redis 控制台查看活动。但我无法使用我怀疑我需要的后端“channels_redis.core.RedisChannelLayer”。
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION' : '<my_azure_redis>.redis.cache.windows.net:6379',
'OPTIONS': {
'PASSWORD': '<mypassword>',
'DB': '1'
},
}
}
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'HOST': '<my_azure_redis>.redis.cache.windows.net',
'PORT': '6379',
'PASSWORD': '<mypassword>',
'SSL' : False,
}
}
}
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '%s:%s' % ("<my_azure_redis>.redis.cache.windows.net", 6379),
'OPTIONS': {
'PASSWORD': "<mypassword>",
'DB': 0,
}
}
}
ASGI_APPLICATION = "django_azure_demo.routing.application"
javascript:
const socket = new WebSocket(
'wss://'
+ window.location.host
+ '/ws/chat/'
+ 'hey'
+ '/'
);
路由.py:
websocket_urlpatterns = [
re_path(r'ws/chat/hey/', consumer.ChatConsumer),
]
asgi.py
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_azure_demo.settings')
application = get_asgi_application()
路由.py
application = ProtocolTypeRouter({
'websocket': AllowedHostsOriginValidator(
AuthMiddlewareStack(
URLRouter(
food.routing.websocket_urlpatterns
)
)
)
})
这一切都在开发中。
我已按照https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-python-get-started开始使用 redis。而且我能够从我的 redis 存储中设置和检索一个变量。
我还在 azure cache 中为 redis 打开了 6379 端口,以允许非 SSL。
我在这里一片空白,不知道下一步该去哪里。感谢您的任何意见!
解决方案
推荐阅读
- image - 如何强制用户嵌入图像或注册
- javascript - 在玩家周围但不在玩家身上产生随机物体
- iis - IIS 8.5 Failed Request Tracing only triggers if request duration is within 1 second of threshold
- spring-boot - Spring Boot JPA, if i have multiple tables with same column name can i put in same entity class?
- c++ - 在 C++ 中的 glutIdleFunc() 中变量值未递增
- python - 查找给定两个位置坐标的中点
- ruby-on-rails - Rails 服务器需要几分钟才能显示第一页
- python - Python:在 Popen 仍在运行时调用函数
- swift - Swift ARKit 你如何完全杀死一个 ARSession?
- python - 为什么 asyncio 的 run_in_executor 在发出 HTTP 请求时很少提供并行化?