Skip to content

Commit fe0db68

Browse files
authored
Improve installation instructions (#1533)
* Number the steps * Separate installation steps from troubleshooting section * Use imperative tone ("Adding the URLs" -> "Add the URLs") * Split prerequisites from adding app * Show example of minimal required template backend * Convert code to black style (double quoted strings) * Simplify wording in several places.
1 parent ea743e0 commit fe0db68

File tree

1 file changed

+65
-33
lines changed

1 file changed

+65
-33
lines changed

docs/installation.rst

+65-33
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
Installation
22
============
33

4+
Process
5+
-------
6+
47
Each of the following steps needs to be configured for the Debug Toolbar to be
58
fully functional.
69

7-
Getting the code
8-
----------------
10+
1. Install the Package
11+
^^^^^^^^^^^^^^^^^^^^^^
912

1013
The recommended way to install the Debug Toolbar is via pip_::
1114

@@ -21,34 +24,60 @@ instead with the following command::
2124

2225
$ python -m pip install -e git+https://github.com/jazzband/django-debug-toolbar.git#egg=django-debug-toolbar
2326

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.
2636

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
3042
3143
INSTALLED_APPS = [
3244
# ...
33-
'django.contrib.staticfiles',
45+
"django.contrib.staticfiles",
3446
# ...
35-
'debug_toolbar',
3647
]
3748
38-
STATIC_URL = '/static/'
49+
STATIC_URL = "static/"
3950
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``:
4353

54+
.. code-block:: python
4455
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+
^^^^^^^^^^^^^^^^^^
4766

48-
Setting up URLconf
49-
------------------
67+
Add ``"debug_toolbar"`` to your ``INSTALLED_APPS`` setting::
5068

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
5281
5382
import debug_toolbar
5483
from django.urls import include, path
@@ -62,15 +91,17 @@ This example uses the ``__debug__`` prefix, but you can use any prefix that
6291
doesn't clash with your application's URLs. Note the lack of quotes around
6392
``debug_toolbar.urls``.
6493

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:
6799

68-
The Debug Toolbar is mostly implemented in a middleware. Enable it in your
69-
settings module as follows::
100+
.. code-block:: python
70101
71102
MIDDLEWARE = [
72103
# ...
73-
'debug_toolbar.middleware.DebugToolbarMiddleware',
104+
"debug_toolbar.middleware.DebugToolbarMiddleware",
74105
# ...
75106
]
76107
@@ -83,36 +114,37 @@ settings module as follows::
83114

84115
.. _internal-ips:
85116

86-
Configuring Internal IPs
87-
------------------------
117+
6. Configure Internal IPs
118+
^^^^^^^^^^^^^^^^^^^^^^^^^
88119

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
90121
: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
94127
95128
INTERNAL_IPS = [
96129
# ...
97-
'127.0.0.1',
130+
"127.0.0.1",
98131
# ...
99132
]
100133
101134
You can change the logic of determining whether or not the Debug Toolbar
102135
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.
104137

105138
.. warning::
106139

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::
108141

109142
if DEBUG:
110143
import os # only if you haven't already imported this
111144
import socket # only if you haven't already imported this
112145
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
113146
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
114147

115-
116148
Troubleshooting
117149
---------------
118150

0 commit comments

Comments
 (0)