Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python heroku主机上的django频道_Python_Django_Django Channels - Fatal编程技术网

Python heroku主机上的django频道

Python heroku主机上的django频道,python,django,django-channels,Python,Django,Django Channels,因为我不能使用redis,所以我使用了另一个通道层,即 内存通道层 WSGI_APPLICATION = 'django_analytics.wsgi.application' ASGI_APPLICATION = "django_analytics.routings.application" CHANNEL_LAYERS = { "default": { "BACKEND": "channels.layers.InMemoryChannelLayer",

因为我不能使用redis,所以我使用了另一个通道层,即 内存通道层

WSGI_APPLICATION = 'django_analytics.wsgi.application'
ASGI_APPLICATION = "django_analytics.routings.application"
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer",
        "CONFIG": {
        },
    },
}
我在heroku上部署了它,但我发现了错误

(索引):9连接到的WebSocket 'wss://mkmnim.herokuapp.com/ws/chat/page/'失败:执行过程中出错 WebSocket握手:意外响应代码:404

我让它在我的本地服务器上工作,但是我不能在网上托管它,我也必须做一些与daphne相关的事情吗? 最初,我使用redis并在本地运行redis服务器,但在托管redis安装时是付费的,所以我选择了MemoryChannel Layer ()

那我该怎么办

django_analytics.routings.py 查看_analytics.routings.py page.html

标题
让chatSocket=新的WebSocket(
'wss://'+window.location.host+
'/ws/chat/'+'页'+'/');
chatSocket.onmessage=函数(e){
const data=JSON.parse(e.data);
常量消息=数据['message'];
console.log(“消息是”+消息)
};
chatSocket.onclose=函数(e){
console.error('聊天套接字意外关闭');
};
编辑1: 还添加了heroku日志

2018-11-13T08:12:14.240908+00:00 heroku[路由器]:at=info-method=GET path=“/view\u analytics/page\u check/”host=mkmnim.herokuapp.com 请求id=93802d36-fece-47b0-9e91-7f453d891f00 fwd=“47.31.181.82” dyno=web.1连接=1ms服务=60ms状态=200字节=726 协议=https 2018-11-13T08:12:14.240275+00:00应用程序[web.1]: 10.41.198.116--[13/Nov/2018:08:12:14+0000]“获取/查看分析/页面检查/HTTP/1.1”200 536“-”Mozilla/5.0(X11; Linux x86_64)AppleWebKit/537.36(KHTML,比如Gecko) Chrome/69.0.3497.81 Safari/537.36“2018-11-13T08:12:15.342043+00:00 heroku[router]:at=info method=GET path=“/ws/chat/page/” host=mkmnim.herokuapp.com 请求id=c2f225eb-1f88-4417-87fe-281b6dd6fd51 fwd=“47.31.181.82” dyno=web.1连接=1ms服务=7ms状态=404字节=2534 协议=https 2018-11-13T08:12:15.340615+00:00应用程序[web.1]:未找到: /ws/chat/page/2018-11-13T08:12:15.341106+00:00应用程序[web.1]: 10.168.81.123--[13/Nov/2018:08:12:15+0000]“GET/ws/chat/page/HTTP/1.1”404 2351“-”Mozilla/5.0(X11;Linux x86_64) AppleWebKit/537.36(KHTML,像Gecko)Chrome/69.0.3497.81 Safari/537.36“


能否显示前端websocket初始化代码?已编辑、添加html:-)请先澄清一些细节。如果它在本地工作,那么它也将在heroku工作,而与MemoryChannel Layer中的
无关。您能否硬刷新本地浏览器并尝试访问本地服务器地址中的页面?是的,它在本地服务器中工作。好的。如果可能,请包括heroku日志。
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from view_analytics import routing

application = ProtocolTypeRouter({
    # Empty for now (http->django views is added by default)
    'websocket': AuthMiddlewareStack(
        URLRouter(
            routing.websocket_urlpatterns
        )
    ),
})
from django.conf.urls import url

from . import consumers

websocket_urlpatterns = [
    url(r'^ws/chat/room/$', consumers.ChatConsumer),
    url(r'^ws/chat/page/$', consumers.PageConsumer),

]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let chatSocket = new WebSocket(
        'wss://' + window.location.host +
        '/ws/chat/' + 'page' + '/');

    chatSocket.onmessage = function(e) {
        const data = JSON.parse(e.data);
        const message = data['message'];
        console.log("message is"+ message)
    };

    chatSocket.onclose = function(e) {
        console.error('Chat socket closed unexpectedly');
    };
</script>

</body>
</html>