Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
5044b804
Unverified
Commit
5044b804
authored
May 07, 2018
by
Diederik van der Boor
Browse files
Allow overriding the 404 page for missing files
parent
d93d2ef1
Changes
1
Hide whitespace changes
Inline
Side-by-side
private_storage/views.py
View file @
5044b804
...
@@ -67,9 +67,23 @@ class PrivateStorageView(View):
...
@@ -67,9 +67,23 @@ class PrivateStorageView(View):
return
HttpResponseForbidden
(
'Private storage access denied'
)
return
HttpResponseForbidden
(
'Private storage access denied'
)
if
not
private_file
.
exists
():
if
not
private_file
.
exists
():
raise
Http404
(
"File not found"
)
return
self
.
serve_file_not_found
(
private_file
)
else
:
return
self
.
serve_file
(
private_file
)
def
serve_file_not_found
(
self
,
private_file
):
"""
Display a response message telling that the file is not found.
This can be overwritten to improve the customer experience.
For example
- redirect the user, and show a message.
- render the message in the expected media type (e.g. PNG).
- show a custom 404 page.
return
self
.
serve_file
(
private_file
)
:type private_file: :class:`private_storage.models.PrivateFile`
:rtype: django.http.HttpResponse
"""
raise
Http404
(
"File not found"
)
def
serve_file
(
self
,
private_file
):
def
serve_file
(
self
,
private_file
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment