Skip to content
Snippets Groups Projects
Commit 4e9d29e6 authored by jan.bednarik's avatar jan.bednarik
Browse files

majak: Custom 404 handlers

parent f753c6b1
No related branches found
No related tags found
2 merge requests!411release,!410Dary
......@@ -100,6 +100,14 @@ Kalendář se stáhne při uložení modelu obsahujícího `CalendarMixin`.
Appka přidává management command `update_callendars`, který stahuje a updatuje
kalendáře. Je třeba ho pravidelně volat na pozadí (přes CRON).
### Stránka 404
Pokud je třeba vlastní 404 pro web, stačí do kořenové `xxxHomePage` webu
definovat metodu `get_404_response` vracející Django HTTP Reponse objekt.
def get_404_response(self, request):
return HttpResponse("Stránka nenalezena", status=404)
## Deployment
### Konfigurace
......
......@@ -10,6 +10,8 @@ from wagtail.documents import urls as wagtaildocs_urls
from elections2021 import views as elections2021_views
from search import views as search_views
handler404 = "shared.views.page_not_found"
urlpatterns = [
url(r"^django-admin/", admin.site.urls),
url(r"^admin/", include(wagtailadmin_urls)),
......
from django.http import HttpResponse
from wagtail.core.models import Site
def page_not_found(request, exception=None):
try:
site = Site.find_for_request(request)
root_page = site.root_page.specific
except:
root_page = None
if root_page and hasattr(root_page, "get_404_response"):
return root_page.get_404_response(request)
return HttpResponse(
"<h1>Stránka nenalezena</h1><a href='/'>pokračovat na úvod</a>",
status=404,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment