App Setup Improvements

The Django debug toolbar

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

Join course for $15

Modified files

pyproject.toml
--- 
+++ 
@@ -10,6 +10,9 @@
 django = "^5.1.3"


+[tool.poetry.group.dev.dependencies]
+django-debug-toolbar = "^4.4.6"
+
 [build-system]
 requires = ["poetry-core"]
 build-backend = "poetry.core.masonry.api"
djangocourse/settings.py
--- 
+++ 
@@ -49,6 +49,22 @@
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
 ]
+
+if DEBUG:
+    INSTALLED_APPS += [
+        "debug_toolbar"
+    ]
+
+    MIDDLEWARE += [
+        "debug_toolbar.middleware.DebugToolbarMiddleware"
+    ]
+
+    import socket
+
+    hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
+
+    INTERNAL_IPS = [ip[:-1] + "1" for ip in ips] + ["127.0.0.1"]
+    INTERNAL_IPS += ["192.168.65.1"]

 ROOT_URLCONF = 'djangocourse.urls'
djangocourse/urls.py
--- 
+++ 
@@ -19,5 +19,6 @@

 urlpatterns = [
     path("admin/", admin.site.urls),
-    path("articles/", include("app.urls"))
+    path("articles/", include("app.urls")),
+    path("__debug__/", include("debug_toolbar.urls"))
 ]