diff --git a/website/common/tests/test_views.py b/website/common/tests/test_views.py index 51c8842..847b07c 100644 --- a/website/common/tests/test_views.py +++ b/website/common/tests/test_views.py @@ -15,6 +15,12 @@ class Error404PageTestCase(TestCase): response, "

There's nothing here!

", html=True, status_code=404 ) + def test_actual_404_no_url_match(self) -> None: + response = self.client.get("/favicon.ico") + self.assertContains( + response, "

There's nothing here!

", html=True, status_code=404 + ) + def test_queries(self) -> None: with self.assertNumQueries(20): self.client.get(self.url) diff --git a/website/common/views.py b/website/common/views.py index b077793..1755781 100644 --- a/website/common/views.py +++ b/website/common/views.py @@ -19,7 +19,8 @@ class Error404View(TemplateView): template_name = ERROR_404_TEMPLATE_NAME def render_to_response(self, context: dict, **response_kwargs: Any) -> HttpResponse: - if self.request.resolver_match.url_name != "404": + resolver_match = self.request.resolver_match + if not resolver_match or resolver_match.url_name != "404": response_kwargs["status"] = 404 return super().render_to_response(context, **response_kwargs)