mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
views: Fix 'internal server error' when showing 404 page
Closes: #2517. Tests: - Without the patch, run without --develop option and visit a non-exiting page like /plinth/foo/. It results in '500 internal server error' instead of 404 non-found error. - With the patch, the '404' page is shown. Breadcrumbs show only a link to the home page with home icon. - Accessing a page like /plinth/apps/bepasty/add?foo redirects it to /plinth/apps/bepasty/add/?foo. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2862862161
commit
9ddb83a741
@ -75,19 +75,26 @@ def get_breadcrumbs(request: HttpRequest) -> dict[str, dict[str, str | bool]]:
|
|||||||
'url_name': url_name
|
'url_name': url_name
|
||||||
}
|
}
|
||||||
|
|
||||||
url_name = request.resolver_match.url_name
|
|
||||||
full_url_name = ':'.join(request.resolver_match.app_names + [url_name])
|
|
||||||
try:
|
try:
|
||||||
menu_item = menu.Menu.get_with_url_name(full_url_name)
|
url_name = request.resolver_match.url_name
|
||||||
except LookupError:
|
full_url_name = ':'.join(request.resolver_match.app_names + [url_name])
|
||||||
# There is no menu entry for this page, find it's app.
|
except AttributeError:
|
||||||
_add(request.path, _('Here'), full_url_name)
|
# 404 page: unknown URL, resolver_match is None. Index is home.
|
||||||
app_url_name = ':'.join(request.resolver_match.app_names + ['index'])
|
menu_item = menu.Menu.get_with_url_name('index')
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
menu_item = menu.Menu.get_with_url_name(app_url_name)
|
menu_item = menu.Menu.get_with_url_name(full_url_name)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
# Don't know which app this page belongs to, assume parent is Home.
|
# There is no menu entry for this page, find it's app.
|
||||||
menu_item = menu.Menu.get_with_url_name('index')
|
_add(request.path, _('Here'), full_url_name)
|
||||||
|
app_url_name = ':'.join(request.resolver_match.app_names +
|
||||||
|
['index'])
|
||||||
|
try:
|
||||||
|
menu_item = menu.Menu.get_with_url_name(app_url_name)
|
||||||
|
except LookupError:
|
||||||
|
# Don't know which app this page belongs to, assume parent is
|
||||||
|
# Home.
|
||||||
|
menu_item = menu.Menu.get_with_url_name('index')
|
||||||
|
|
||||||
for _number in range(10):
|
for _number in range(10):
|
||||||
_add(menu_item.url, menu_item.name, menu_item.url_name)
|
_add(menu_item.url, menu_item.name, menu_item.url_name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user