From 12ebf9948b5a959272e423d6219991099d77b82b Mon Sep 17 00:00:00 2001 From: ot-nemoto <41175383+ot-nemoto@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:03:23 +0900 Subject: [PATCH] add django-debug-toolbar --- README.md | 33 +++++++++++++++++++++++++++++++++ mysite/settings.py | 6 ++++++ mysite/urls.py | 3 ++- requirements.txt | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44637b5..7a61787 100644 --- a/README.md +++ b/README.md @@ -137,3 +137,36 @@ coverage report coverage html # Wrote HTML report to htmlcov/index.html ``` + +### Writing your first Django app, part 8 + +**django-debug-toolbar** + +_settings.py_ + +```python +INSTALLED_APPS = [ + ... + 'debug_toolbar', +] + +MIDDLEWARE = [ + ... + 'debug_toolbar.middleware.DebugToolbarMiddleware', +] + +INTERNAL_IPS = [ + '127.0.0.1', +] +``` + +_urls.py_ + +```python +from django.urls import path, include + +urlpatterns = [ + ... + path('__debug__/', include('debug_toolbar.urls')), +] +``` diff --git a/mysite/settings.py b/mysite/settings.py index 8410c5b..66d3b52 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -38,6 +38,7 @@ "django.contrib.messages", # A messaging framework. "django.contrib.staticfiles", # A framework for managing static files. "polls.apps.PollsConfig", + "debug_toolbar", ] MIDDLEWARE = [ @@ -48,6 +49,7 @@ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "debug_toolbar.middleware.DebugToolbarMiddleware", ] ROOT_URLCONF = "mysite.urls" @@ -126,3 +128,7 @@ # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +INTERNAL_IPS = [ + "127.0.0.1", +] diff --git a/mysite/urls.py b/mysite/urls.py index dc08720..89a382e 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -4,4 +4,5 @@ urlpatterns = [ path("polls/", include("polls.urls")), path("admin/", admin.site.urls), -] \ No newline at end of file + path("__debug__/", include("debug_toolbar.urls")), +] diff --git a/requirements.txt b/requirements.txt index 86270bb..811fab2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ django mysqlclient coverage +django-debug-toolbar