Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
4e9d29e6
Commit
4e9d29e6
authored
3 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
majak: Custom 404 handlers
parent
f753c6b1
No related branches found
No related tags found
2 merge requests
!411
release
,
!410
Dary
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+8
-0
8 additions, 0 deletions
README.md
majak/urls.py
+2
-0
2 additions, 0 deletions
majak/urls.py
shared/views.py
+18
-0
18 additions, 0 deletions
shared/views.py
with
28 additions
and
0 deletions
README.md
+
8
−
0
View file @
4e9d29e6
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
majak/urls.py
+
2
−
0
View file @
4e9d29e6
...
...
@@ -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
)),
...
...
This diff is collapsed.
Click to expand it.
shared/views.py
0 → 100644
+
18
−
0
View file @
4e9d29e6
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
,
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment