1
1
Installation
2
2
============
3
3
4
+ Process
5
+ -------
6
+
4
7
Each of the following steps needs to be configured for the Debug Toolbar to be
5
8
fully functional.
6
9
7
- Getting the code
8
- ----------------
10
+ 1. Install the Package
11
+ ^^^^^^^^^^^^^^^^^^^^^^
9
12
10
13
The recommended way to install the Debug Toolbar is via pip _::
11
14
@@ -21,34 +24,60 @@ instead with the following command::
21
24
22
25
$ python -m pip install -e git+https://github.com/jazzband/django-debug-toolbar.git#egg=django-debug-toolbar
23
26
24
- Prerequisites
25
- -------------
27
+ If you're upgrading from a previous version, you should review the
28
+ :doc: `change log <changes >` and look for specific upgrade instructions.
29
+
30
+ 2. Check for Prerequisites
31
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
32
+
33
+ The Debug Toolbar requires two things from core Django. These are already
34
+ configured in Django’s default ``startproject `` template, so in most cases you
35
+ will already have these set up.
26
36
27
- Make sure that ``'django.contrib.staticfiles' `` is `set up properly
28
- <https://docs.djangoproject.com/en/stable/howto/static-files/> `_ and add
29
- ``'debug_toolbar' `` to your ``INSTALLED_APPS `` setting::
37
+ First, ensure that ``'django.contrib.staticfiles' `` is in your
38
+ ``INSTALLED_APPS `` setting, and `configured properly
39
+ <https://docs.djangoproject.com/en/stable/howto/static-files/> `_:
40
+
41
+ .. code-block :: python
30
42
31
43
INSTALLED_APPS = [
32
44
# ...
33
- ' django.contrib.staticfiles' ,
45
+ " django.contrib.staticfiles" ,
34
46
# ...
35
- 'debug_toolbar',
36
47
]
37
48
38
- STATIC_URL = '/ static/'
49
+ STATIC_URL = " static/"
39
50
40
- Make sure your ``TEMPLATES `` setting contains a ``DjangoTemplates `` backend
41
- whose ``APP_DIRS `` options is set to ``True ``. It's in there by default, so
42
- you'll only need to change this if you've changed that setting.
51
+ Second, ensure that your ``TEMPLATES `` setting contains a
52
+ ``DjangoTemplates `` backend whose ``APP_DIRS `` options is set to ``True ``:
43
53
54
+ .. code-block :: python
44
55
45
- If you're upgrading from a previous version, you should review the
46
- :doc: `change log <changes >` and look for specific upgrade instructions.
56
+ TEMPLATES = [
57
+ {
58
+ " BACKEND" : " django.template.backends.django.DjangoTemplates" ,
59
+ " APP_DIRS" : True ,
60
+ # ...
61
+ }
62
+ ]
63
+
64
+ 3. Install the App
65
+ ^^^^^^^^^^^^^^^^^^
47
66
48
- Setting up URLconf
49
- ------------------
67
+ Add ``"debug_toolbar" `` to your ``INSTALLED_APPS `` setting::
50
68
51
- Add the Debug Toolbar's URLs to your project's URLconf::
69
+ INSTALLED_APPS = [
70
+ # ...
71
+ "debug_toolbar",
72
+ # ...
73
+ ]
74
+
75
+ 4. Add the URLs
76
+ ^^^^^^^^^^^^^^^
77
+
78
+ Add django-debug-toolbar's URLs to your project's URLconf:
79
+
80
+ .. code-block :: python
52
81
53
82
import debug_toolbar
54
83
from django.urls import include, path
@@ -62,15 +91,17 @@ This example uses the ``__debug__`` prefix, but you can use any prefix that
62
91
doesn't clash with your application's URLs. Note the lack of quotes around
63
92
``debug_toolbar.urls ``.
64
93
65
- Enabling middleware
66
- -------------------
94
+ 5. Add the Middleware
95
+ ^^^^^^^^^^^^^^^^^^^^^
96
+
97
+ The Debug Toolbar is mostly implemented in a middleware. Add it to your
98
+ ``MIDDLEWARE `` setting:
67
99
68
- The Debug Toolbar is mostly implemented in a middleware. Enable it in your
69
- settings module as follows::
100
+ .. code-block :: python
70
101
71
102
MIDDLEWARE = [
72
103
# ...
73
- ' debug_toolbar.middleware.DebugToolbarMiddleware' ,
104
+ " debug_toolbar.middleware.DebugToolbarMiddleware" ,
74
105
# ...
75
106
]
76
107
@@ -83,36 +114,37 @@ settings module as follows::
83
114
84
115
.. _internal-ips :
85
116
86
- Configuring Internal IPs
87
- ------------------------
117
+ 6. Configure Internal IPs
118
+ ^^^^^^^^^^^^^^^^^^^^^^^^^
88
119
89
- The Debug Toolbar is shown only if your IP address is listed in the
120
+ The Debug Toolbar is shown only if your IP address is listed in Django’s
90
121
:setting: `INTERNAL_IPS ` setting. This means that for local
91
- development, you *must * add ``'127.0.0.1' `` to :setting: `INTERNAL_IPS `;
92
- you'll need to create this setting if it doesn't already exist in your
93
- settings module::
122
+ development, you *must * add ``"127.0.0.1" `` to :setting: `INTERNAL_IPS `.
123
+ You'll need to create this setting if it doesn't already exist in your
124
+ settings module:
125
+
126
+ .. code-block :: python
94
127
95
128
INTERNAL_IPS = [
96
129
# ...
97
- ' 127.0.0.1' ,
130
+ " 127.0.0.1" ,
98
131
# ...
99
132
]
100
133
101
134
You can change the logic of determining whether or not the Debug Toolbar
102
135
should be shown with the :ref: `SHOW_TOOLBAR_CALLBACK <SHOW_TOOLBAR_CALLBACK >`
103
- option. This option allows you to specify a custom function for this purpose.
136
+ option.
104
137
105
138
.. warning ::
106
139
107
- If using Docker the following will set your `INTERNAL_IPS ` correctly only if you are in Debug mode. ::
140
+ If using Docker the following will set your `` INTERNAL_IPS `` correctly in Debug mode::
108
141
109
142
if DEBUG:
110
143
import os # only if you haven't already imported this
111
144
import socket # only if you haven't already imported this
112
145
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
113
146
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
114
147
115
-
116
148
Troubleshooting
117
149
---------------
118
150
0 commit comments