Add debug toolbar

This commit is contained in:
Jake Howard 2022-06-14 22:23:44 +01:00
parent d4b9638a94
commit d5d0b293f7
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 19 additions and 1 deletions

View file

@ -1,5 +1,7 @@
from typing import Type
from django.conf import settings
from django.http.request import HttpRequest
from wagtail.models import Page
from wagtail.models import get_page_models as get_wagtail_page_models
@ -8,3 +10,7 @@ def get_page_models() -> list[Type[Page]]:
page_models = get_wagtail_page_models().copy()
page_models.remove(Page)
return page_models
def show_toolbar_callback(request: HttpRequest) -> bool:
return settings.DEBUG

View file

@ -135,7 +135,16 @@ WAGTAILSEARCH_BACKENDS = {
BASE_HOSTNAME = env("BASE_HOSTNAME")
WAGTAILADMIN_BASE_URL = f"https://{BASE_HOSTNAME}"
# Add `django-browser-reload`
if DEBUG:
# Add django-browser-reload
INSTALLED_APPS.append("django_browser_reload")
MIDDLEWARE.append("django_browser_reload.middleware.BrowserReloadMiddleware")
# Add django-debug-toolbar
INSTALLED_APPS.append("debug_toolbar")
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK": "website.common.utils.show_toolbar_callback",
"RESULTS_CACHE_SIZE": 5,
"SHOW_COLLAPSED": True,
}

View file

@ -24,6 +24,9 @@ if settings.DEBUG:
# Add django-browser-reload
urlpatterns.append(path("__reload__/", include("django_browser_reload.urls")))
# Add django-debug-toolbar
urlpatterns.append(path("__debug__/", include("debug_toolbar.urls")))
urlpatterns = urlpatterns + [
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in