Skip to content
12 changes: 12 additions & 0 deletions debug_toolbar/panels/redirects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from inspect import iscoroutine

from django.template.response import SimpleTemplateResponse
Expand All @@ -17,6 +18,17 @@ class RedirectsPanel(Panel):

nav_title = _("Intercept redirects")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
warnings.warn(
"The RedirectsPanel is deprecated and will be removed in a future version. "
"The HistoryPanel now provides the ability to view toolbar data for redirected requests. "
"If you still have a use case for this panel, please comment on "
"https://github.com/django-commons/django-debug-toolbar/issues/2216",
DeprecationWarning,
stacklevel=2,
)

def _process_response(self, response):
"""
Common response processing logic.
Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Pending
* Upgraded CI ``postgis`` version to 17-3.5.
* Added how to generate the documentation locally to the contributing
documentation.
* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing
toolbar data from redirected requests.

6.0.0 (2025-07-22)
------------------
Expand Down
7 changes: 7 additions & 0 deletions docs/panels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ Redirects

.. class:: debug_toolbar.panels.redirects.RedirectsPanel

.. deprecated:: 6.0

The RedirectsPanel is deprecated and will be removed in a future version.
The HistoryPanel now provides the ability to view toolbar data for redirected
requests. If you have a use case for this panel, please comment on the
GitHub issue <https://github.com/django-commons/django-debug-toolbar/issues/2216>`_.

When this panel is enabled, the debug toolbar will show an intermediate page
upon redirect so you can view any debug information prior to redirecting. This
page will provide a link to the redirect destination you can follow when
Expand Down
18 changes: 18 additions & 0 deletions tests/panels/test_redirects.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import copy
import warnings

from django.conf import settings
from django.http import HttpResponse
from django.test import AsyncRequestFactory

from debug_toolbar.panels.redirects import RedirectsPanel
from debug_toolbar.toolbar import DebugToolbar

from ..base import BaseTestCase


class RedirectsPanelTestCase(BaseTestCase):
panel_id = RedirectsPanel.panel_id

def setUp(self):
# Suppress the deprecation warning during setup
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
super().setUp()

def test_regular_response(self):
not_redirect = HttpResponse()
self._get_response = lambda request: not_redirect
Expand Down Expand Up @@ -100,3 +108,13 @@ def test_original_response_preserved(self):
self.assertEqual(
response.original_response.get("Location"), "http://somewhere/else/"
)

def test_deprecation_warning(self):
"""Test that a deprecation warning is shown when RedirectsPanel is instantiated."""

with self.assertWarns(DeprecationWarning) as cm:
toolbar = DebugToolbar(self.request, self._get_response)
toolbar.get_panel_by_id(RedirectsPanel.panel_id)

self.assertIn("RedirectsPanel is deprecated", str(cm.warning))
self.assertIn("HistoryPanel", str(cm.warning))