Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions debug_toolbar/panels/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from pprint import pformat

from django.utils.translation import gettext_lazy as _
from django.views.debug import get_default_exception_reporter_filter

from debug_toolbar.panels import Panel
from debug_toolbar.sanitize import force_str

get_safe_settings = get_default_exception_reporter_filter().get_safe_settings


def safe_pformat(obj):
try:
return pformat(obj)
except Exception as e:
return f"<unformattable {type(obj).__name__}: {e!r}>"


class SettingsPanel(Panel):
"""
A panel to display all variables in django.conf.settings
Expand All @@ -27,7 +35,7 @@ def generate_stats(self, request, response):
self.record_stats(
{
"settings": {
key: force_str(value)
key: safe_pformat(value)
for key, value in sorted(get_safe_settings().items())
}
}
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% for name, value in settings.items %}
<tr>
<td>{{ name }}</td>
<td><code>{{ value|pprint }}</code></td>
<td><code>{{ value }}</code></td>
</tr>
{% endfor %}
</tbody>
Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Pending
``debug_toolbar.store.DatabaseStore`` with ``SKIP_TOOLBAR_QUERIES``.
* Fixed font family for code blocks and stack traces in the toolbar.
* Added test to confirm Django's ``TestCase.assertNumQueries`` works.
* Fixed display of values in settings panel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more specific? Not sure if that's an improvement, just a suggestion.

Suggested change
* Fixed display of values in settings panel.
* Fixed double quoting of values in settings panel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work better?

Fixed string representation of values in settings panel


6.1.0 (2025-10-30)
------------------
Expand Down
23 changes: 21 additions & 2 deletions tests/panels/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
from django.test import override_settings
from django.test import RequestFactory, override_settings

from ..base import IntegrationTestCase
from debug_toolbar.panels.settings import SettingsPanel

from ..base import BaseTestCase, IntegrationTestCase

rf = RequestFactory()


class SettingsPanelTestCase(BaseTestCase):
panel_id = SettingsPanel.panel_id

def test_panel_recording(self):
self.request = rf.post("/", data={"foo": "bar"})
response = self.panel.process_request(self.request)
self.panel.generate_stats(self.request, response)

settings = self.panel.get_stats()["settings"]
self.assertEqual(settings["USE_THOUSAND_SEPARATOR"], "False")
self.assertEqual(settings["ABSOLUTE_URL_OVERRIDES"], "{}")
self.assertEqual(settings["EMAIL_HOST"], "'localhost'")
self.assertEqual(settings["EMAIL_PORT"], "25")


@override_settings(DEBUG=True)
Expand Down
Loading