mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #24829 -- Allowed use of TemplateResponse in view error handlers.
This commit is contained in:
parent
64a4211aa8
commit
2f615b10e6
4 changed files with 44 additions and 0 deletions
30
tests/handlers/tests_custom_error_handlers.py
Normal file
30
tests/handlers/tests_custom_error_handlers.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django.conf.urls import url
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.template.response import TemplateResponse
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
|
||||
def template_response_error_handler(request, exception=None):
|
||||
return TemplateResponse(request, 'test_handler.html', status=403)
|
||||
|
||||
|
||||
def permission_denied_view(request):
|
||||
raise PermissionDenied
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', permission_denied_view),
|
||||
]
|
||||
|
||||
handler403 = template_response_error_handler
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='handlers.tests_custom_error_handlers')
|
||||
class CustomErrorHandlerTests(SimpleTestCase):
|
||||
|
||||
def test_handler_renders_template_response(self):
|
||||
"""
|
||||
BaseHandler should render TemplateResponse if necessary.
|
||||
"""
|
||||
response = self.client.get('/')
|
||||
self.assertContains(response, 'Error handler content', status_code=403)
|
Loading…
Add table
Add a link
Reference in a new issue