它在我的本地主机上工作。但是当我在AWS ElasticBeanstalk上进行部署时,会出现以下错误:
Traceback (most recent call last):
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 523, in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<URLPattern '^$' [name='home']>], [<URLPattern '^comunidade/'>]], 'path': 'socket/comunidade/'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 99, in get_exception_response
response = callback(request, **dict(param_dict, exception=exception))
TypeError: handler404() got an unexpected keyword argument 'exception'
我的routing.py:
application = ProtocolTypeRouter({
"websocket": OriginValidator(
AuthMiddlewareStack(
URLRouter([
# URLRouter just takes standard Django path() or url() entries.
path("socket/", MyConsumer),
url("socket/(?P<slug>[\w-]+)", MyConsumer),
]),
),
[".mydomain.com.br", "localhost"]
),
})
我的JS连接:
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var connection = new WebSocket( ws_scheme + "://" + window.location.host + "/socket" + window.location.pathname );
在AWS配置中,WSGIPath指向wsgi.py
。似乎是将频道2路由到urls.py