Use _serve_file to serve custom 404 page
@@ -12,7 +12,7 @@ import os
import logging
from django.conf import settings
-from django.http import HttpResponseRedirect, Http404, JsonResponse, HttpResponse
+from django.http import HttpResponseRedirect, Http404, JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
from django.views.generic import TemplateView
@@ -21,6 +21,7 @@ from readthedocs.builds.models import Version
from readthedocs.core.resolver import resolve_path
from readthedocs.core.symlink import PrivateSymlink, PublicSymlink
from readthedocs.core.utils import broadcast
+from readthedocs.core.views.serve import _serve_file
from readthedocs.projects.constants import PRIVATE
from readthedocs.projects.models import Project, ImportedFile
from readthedocs.projects.tasks import remove_dirs
@@ -153,8 +154,8 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli
fullpath = os.path.join(basepath, filename)
if os.path.exists(fullpath):
- log.debug('Serving custom 404.html page for project: %', project.slug)
- r = HttpResponse(open(fullpath).read(), content_type='text/html')
+ log.info('Serving custom 404.html page for project: %', project.slug)
+ r = _serve_file(request, filename, basepath)
else:
# Return the default 404 page generated by Read the Docs
r = render(request, template_name)
