当我的使用者的任何部分出现异常时,Django-Channels都无法在控制台中显示异常错误。
发生异常时,它仅在控制台中显示“ WebSocket DISCONNECT / ws / test / [127.0.0.1:7907]”。
我使用以下命令运行带有debug = True设置的项目:
python3 manage.py runserver
我对django通道使用基本设置:
# CHANNELS
# ------------------------------------------------------------------------------
ASGI_APPLICATION = "config.routing.application"
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
,并且有一个非常简单的测试对象:
class Test(WebsocketConsumer):
def connect(self):
print(self.scope['headers']) # show headers in console.
raise Exception('test exception') # this line doesn't show any thing in console. just show disconnect message.
self.accept()
def receive(self, text_data=None, bytes_data=None):
print(text_data)
和路由:
application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
orders.routing.websocket_urlpatterns
)
),
})
答案 0 :(得分:0)
我发现了问题。当我使用debug_toolbar应用程序时,Django通道无法在控制台中记录异常。我从INSTALLED_APPS中删除了debug_toolbar,然后问题解决了。
这是我的debug_toolbar配置:
# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
INSTALLED_APPS += ['debug_toolbar'] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] # noqa F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
'DISABLE_PANELS': [
'debug_toolbar.panels.redirects.RedirectsPanel',
],
'SHOW_TEMPLATE_CONTEXT': True,
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ['127.0.0.1', '10.0.2.2']