Skip to content

Fix erroneous ContentNotRenderedError raised by the redirects panel #1010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2017
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
1 change: 1 addition & 0 deletions debug_toolbar/panels/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def process_response(self, request, response):
# Using SimpleTemplateResponse avoids running global context processors.
response = SimpleTemplateResponse('debug_toolbar/redirect.html', context)
response.cookies = cookies
response.render()
return response
5 changes: 5 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change log
==========

UNRELEASED
----------

* Fix erroneous ``ContentNotRenderedError`` raised by the redirects panel.

1.9
---

Expand Down
11 changes: 11 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ def test_data_store_id_not_rendered_when_none(self):
self.assertIn(b'id="djDebug"', response.content)
self.assertNotIn(b'data-store-id', response.content)

def test_view_returns_template_response(self):
response = self.client.get('/template_response/basic/')
self.assertEqual(response.status_code, 200)

@override_settings(DEBUG_TOOLBAR_CONFIG={'DISABLE_PANELS': set()})
def test_incercept_redirects(self):
response = self.client.get('/redirect/')
self.assertEqual(response.status_code, 200)
# Link to LOCATION header.
self.assertIn(b'href="/regular/redirect/"', response.content)


@unittest.skipIf(webdriver is None, "selenium isn't installed")
@unittest.skipUnless('DJANGO_SELENIUM_TESTS' in os.environ, "selenium tests not requested")
Expand Down
2 changes: 2 additions & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
url(r'^resolving2/(?P<arg1>.+)/(?P<arg2>.+)/$', views.resolving_view),
url(r'^resolving3/(.+)/$', views.resolving_view, {'arg2': 'default'}),
url(r'^regular/(?P<title>.*)/$', views.regular_view),
url(r'^template_response/(?P<title>.*)/$', views.template_response_view),
url(r'^regular_jinja/(?P<title>.*)/$', views.regular_jinjia_view),
url(r'^non_ascii_request/$', views.regular_view, {'title': NonAsciiRepr()}),
url(r'^new_user/$', views.new_user),
url(r'^execute_sql/$', views.execute_sql),
url(r'^cached_view/$', views.cached_view),
url(r'^redirect/$', views.redirect_view),
url(r'^__debug__/', include(debug_toolbar.urls)),
]
11 changes: 10 additions & 1 deletion tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import absolute_import, unicode_literals

from django.contrib.auth.models import User
from django.http import HttpResponse
from django.http import HttpResponse, HttpResponseRedirect
from django.template.response import TemplateResponse
from django.shortcuts import render
from django.views.decorators.cache import cache_page

Expand All @@ -17,6 +18,10 @@ def regular_view(request, title):
return render(request, 'basic.html', {'title': title})


def template_response_view(request, title):
return TemplateResponse(request, 'basic.html', {'title': title})


def new_user(request, username='joe'):
User.objects.create_user(username=username)
return render(request, 'basic.html', {'title': 'new user'})
Expand All @@ -39,3 +44,7 @@ def regular_jinjia_view(request, title):
def listcomp_view(request):
lst = [i for i in range(50000) if i % 2 == 0]
return render(request, 'basic.html', {'title': 'List comprehension', 'lst': lst})


def redirect_view(request):
return HttpResponseRedirect('/regular/redirect/')