Return 200 when viewing the dedicated 404 page

This commit is contained in:
Jake Howard 2022-08-19 15:07:59 +01:00
parent f452f5deed
commit cd4252cd64
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 10 additions and 3 deletions

View file

@ -7,10 +7,16 @@ class Error404PageTestCase(TestCase):
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 404)
self.assertContains(response, "<h1>There's nothing here!</h1>", html=True)
def test_actual_404(self) -> None:
response = self.client.get("/does-not-exist/")
self.assertContains(
response, "<h1>There's nothing here!</h1>", html=True, status_code=404
)
def test_queries(self) -> None:
with self.assertNumQueries(10):
with self.assertNumQueries(8):
self.client.get(self.url)

View file

@ -15,7 +15,8 @@ class Error404View(TemplateView):
template_name = ERROR_404_TEMPLATE_NAME
def render_to_response(self, context: dict, **response_kwargs: Any) -> HttpResponse:
response_kwargs["status"] = 404
if self.request.resolver_match.url_name != "404":
response_kwargs["status"] = 404
return super().render_to_response(context, **response_kwargs)
def get_context_data(self, **kwargs: dict) -> dict: