1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #34830 -- Added request to bad_request/csrf_failure view template contexts.

This commit is contained in:
yushanfans2233
2023-11-11 15:24:24 +08:00
committed by Mariusz Felisiak
parent 8fcb9f1f10
commit 14b0132e5e
4 changed files with 29 additions and 3 deletions

View File

@@ -112,6 +112,7 @@ class CsrfViewTests(SimpleTestCase):
"""A custom CSRF_FAILURE_TEMPLATE_NAME is used."""
response = self.client.post("/")
self.assertContains(response, "Test template for CSRF failure", status_code=403)
self.assertIs(response.wsgi_request, response.context.request)
def test_custom_template_does_not_exist(self):
"""An exception is raised if a nonexistent template is supplied."""

View File

@@ -102,6 +102,29 @@ class DefaultsTests(TestCase):
response = bad_request(request, Exception())
self.assertContains(response, b"<h1>Bad Request (400)</h1>", status_code=400)
@override_settings(
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"OPTIONS": {
"loaders": [
(
"django.template.loaders.locmem.Loader",
{
"400.html": (
"This is a test template for a 400 error "
),
},
),
],
},
}
]
)
def test_custom_bad_request_template(self):
response = self.client.get("/raises400/")
self.assertIs(response.wsgi_request, response.context[-1].request)
@override_settings(
TEMPLATES=[
{