1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

fix: render the 404 page for logged-in users

app_active and view_active read request.resolver_match, which is None
when no URL matched, so the navbar raised AttributeError and the 404
became a 500.
This commit is contained in:
catborise 2026-10-03 10:23:53 +03:00
parent fd5aa069be
commit 61208606f7
2 changed files with 14 additions and 2 deletions

View file

@ -7,12 +7,15 @@ register = template.Library()
@register.simple_tag
def app_active(request, app_name):
return "active" if request.resolver_match.app_name == app_name else ""
# resolver_match is None on error pages such as 404
match = request.resolver_match
return "active" if match and match.app_name == app_name else ""
@register.simple_tag
def view_active(request, view_name):
return "active" if request.resolver_match.view_name == view_name else ""
match = request.resolver_match
return "active" if match and match.view_name == view_name else ""
@register.simple_tag

View file

@ -0,0 +1,9 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
class NotFoundPageTestCase(TestCase):
def test_unknown_url_renders_404_for_logged_in_user(self):
user = get_user_model().objects.create_user("tags_user", "t@example.com", "pw")
self.client.force_login(user)
self.assertEqual(self.client.get("/no-such-page/").status_code, 404)