I'm trying to incorporate django-channels into my next project but I am having issues debugging. I have tried pycharms debugger and also pdb but it does not hit the breakpoints.
Press Shift + F9 to run the configuration in Debug mode. You can also directly click on the Bug sign on the top bar. Add some breakpoints in the code of the Django project. In my case, I've added a breakpoint in a viewset of my Django projects.
What is Django Channels? Django Channels (or just Channels) extends the built-in capabilities of Django allowing Django projects to handle not only HTTP but also protocols that require long-running connections, such as WebSockets, MQTT (IoT), chatbots, radios, and other real-time applications.
One of the main features of debug mode is the display of detailed error pages. If your app raises an exception when DEBUG is True, Django will display a detailed traceback, including a lot of metadata about your environment, such as all the currently defined Django settings (from settings.py).
Take a look into django channels panel. It is a plugin to django debug toolbar. You can add django-channels-panel to this to add channel debug functionality to your project. This ensures that you can channel details when your app is in development mode.
https://github.com/Krukov/django-channels-panel
Installation [ Django debug toolbar ]
pip install django-debug-toolbar
In settings.py
INSTALLED_APPS = [
# ...
'django.contrib.staticfiles',
# ...
'debug_toolbar',
]
MIDDLEWARE = [
# ...
'debug_toolbar.middleware.DebugToolbarMiddleware',
# ...
]
In urls.py
from django.conf import settings
from django.conf.urls import include, url
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
Configuration
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
]
Installation [ Django channels panel ]
pip install django-channels-panel
add 'channels_panel' to your INSTALLED_APPS in settings.py
add 'channels_panel.panel.ChannelsDebugPanel' to your DEBUG_TOOLBAR_PANELS
Adding PYCHARM_DEBUG=True to the environment variables solved this for me.
This adds a lot of extra logging to be outputted when running the debugger, but it seems that the problem remains fixed even after removing the PYCHARM_DEBUG value from the config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With