Fix 404s if there's no resolver match
This commit is contained in:
parent
f40681d06a
commit
a76b9df329
2 changed files with 8 additions and 1 deletions
|
@ -15,6 +15,12 @@ class Error404PageTestCase(TestCase):
|
|||
response, "<h1>There's nothing here!</h1>", html=True, status_code=404
|
||||
)
|
||||
|
||||
def test_actual_404_no_url_match(self) -> None:
|
||||
response = self.client.get("/favicon.ico")
|
||||
self.assertContains(
|
||||
response, "<h1>There's nothing here!</h1>", html=True, status_code=404
|
||||
)
|
||||
|
||||
def test_queries(self) -> None:
|
||||
with self.assertNumQueries(20):
|
||||
self.client.get(self.url)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue