How to do it...

Follow these steps to set up the Django Debug Toolbar, which can be switched on or off using a bookmarklet in the browser:

  1. Add the following project settings:
# settings.py or conf/base.py
MIDDLEWARE = ( # ... "debug_toolbar.middleware.DebugToolbarMiddleware", ) DEBUG_TOOLBAR_CONFIG = { "DISABLE_PANELS": [], "SHOW_TOOLBAR_CALLBACK": "utils.misc.custom_show_toolbar", "SHOW_TEMPLATE_CONTEXT": True, } 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.templates.TemplatesPanel", "debug_toolbar.panels.staticfiles.StaticFilesPanel", "debug_toolbar.panels.cache.CachePanel", "debug_toolbar.panels.signals.SignalsPanel", "debug_toolbar.panels.logging.LoggingPanel", "debug_toolbar.panels.redirects.RedirectsPanel", ]
  1. In the utils module, create a misc.py file with the custom_show_toolbar() function, as follows:
# utils/misc.py
def custom_show_toolbar(request):
return "1" == request.COOKIES.get("DebugToolbar", False)
  1. Open the Chrome or Firefox browser and go to the bookmark manager. Then, create two new bookmarks that contain JavaScript. The first link will show the toolbar, and will look similar to the following:

  1. The second JavaScript link will hide the toolbar, and will look similar to the following:

If you wish to copy and paste the preceding scripts, they are as follows, with the major difference highlighted in bold:
  • On: javascript:(function(){document.cookie="DebugToolbar=1; path=/";location.reload();})();
  • Off: javascript:(function(){document.cookie="DebugToolbar=0; path=/";location.reload();})();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.242.141