Skip to content

Commit c32422a

Browse files
committed
Use _serve_file to serve custom 404 page
1 parent 8f94b28 commit c32422a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

readthedocs/core/views/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import logging
1313

1414
from django.conf import settings
15-
from django.http import HttpResponseRedirect, Http404, JsonResponse, HttpResponse
15+
from django.http import HttpResponseRedirect, Http404, JsonResponse
1616
from django.shortcuts import render, get_object_or_404, redirect
1717
from django.views.generic import TemplateView
1818

@@ -21,6 +21,7 @@
2121
from readthedocs.core.resolver import resolve_path
2222
from readthedocs.core.symlink import PrivateSymlink, PublicSymlink
2323
from readthedocs.core.utils import broadcast
24+
from readthedocs.core.views.serve import _serve_file
2425
from readthedocs.projects.constants import PRIVATE
2526
from readthedocs.projects.models import Project, ImportedFile
2627
from readthedocs.projects.tasks import remove_dirs
@@ -153,8 +154,8 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli
153154
fullpath = os.path.join(basepath, filename)
154155

155156
if os.path.exists(fullpath):
156-
log.debug('Serving custom 404.html page for project: %', project.slug)
157-
r = HttpResponse(open(fullpath).read(), content_type='text/html')
157+
log.info('Serving custom 404.html page for project: %', project.slug)
158+
r = _serve_file(request, filename, basepath)
158159
else:
159160
# Return the default 404 page generated by Read the Docs
160161
r = render(request, template_name)

0 commit comments

Comments
 (0)