Skip to content
Merged
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: 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
60 changes: 60 additions & 0 deletions debug_toolbar/templates/debug_toolbar/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,68 @@
<head>
<title>Django Debug Toolbar Redirects Panel: {{ status_line }}</title>
<script{% if toolbar.csp_nonce %} nonce="{{ toolbar.csp_nonce }}"{% endif %} type="module" src="{% static 'debug_toolbar/js/redirect.js' %}" async></script>
<style>
.djdt-deprecation-warning {
--djdt-warning-bg: #fff3cd;
--djdt-warning-text: #856404;
--djdt-warning-accent: #f1c40f;
--djdt-warning-link: #0056b3;
--djdt-warning-link-hover: #003d7a;
--djdt-warning-strong: #000;
--djdt-warning-shadow: rgba(0, 0, 0, 0.1);

position: relative;
background-color: var(--djdt-warning-bg);
color: var(--djdt-warning-text);
border-left: 0.25em solid var(--djdt-warning-accent);
padding: 1em;
margin: 1.5em 0;
border-radius: 0.25em;
box-shadow:
0 0.0625em 0.1875em var(--djdt-warning-shadow),
0 0.0625em 0.125em var(--djdt-warning-shadow);
font-family: var(--djdt-font-family-primary);
font-size: 0.875em;
line-height: 1.5;
}

.djdt-deprecation-warning::before {
content: "⚠️";
font-size: 1.125em;
margin-right: 0.75em;
vertical-align: middle;
}

.djdt-deprecation-warning a {
color: var(--djdt-warning-link);
text-decoration: none;
font-weight: 500;
border-bottom: 0.0625em solid currentColor;
padding-bottom: 0.0625em;
transition: all 0.2s ease;
}

.djdt-deprecation-warning a:hover {
color: var(--djdt-warning-link-hover);
border-bottom-width: 0.125em;
}

.djdt-deprecation-warning strong {
color: var(--djdt-warning-strong);
font-weight: 600;
}
</style>
</head>
<body>
<div class="djdt-deprecation-warning">
<strong>{% translate "WARNING:" %}</strong>
{% blocktranslate with issue_url="https://github.com/django-commons/django-debug-toolbar/issues/2216" %}
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 this <a target="_blank" rel="noopener noreferrer"
href="{{ issue_url }}">issue</a>.
{% endblocktranslate %}
</div>
<h1>{{ status_line }}</h1>
<h2>{% translate "Location:" %} <a id="redirect_to" href="{{ redirect_to }}">{{ redirect_to }}</a></h2>
<p class="notice">
Expand Down
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change log
Pending
-------

* Deprecated ``RedirectsPanel`` in favor of ``HistoryPanel`` for viewing
toolbar data from redirected requests.

6.1.0 (2025-10-30)
------------------

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))