We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Serve custom 404 pages from Django
Currently, we are serving the `404.html` from NGINX returning a `Response` that includes the `X-Accel-Redirect` header:

https://github.com/rtfd/readthedocs.org/blob/537f7b8d2e8d81f8243d1d4a562968e472bc6337/readthedocs/core/views/__init__.py#L208-L210

We found that even marking the `response.status_code = 404`, the response is 200.

```
$ curl -IL https://docs.readthedocs.io/notfound
HTTP/1.1 200 OK
Content-Length: 14167
Content-Type: text/html
Last-Modified: Mon, 22 Apr 2019 15:30:57 GMT
Accept-Ranges: bytes
ETag: "5cbdde31-3757"
Vary: Accept-Encoding
Server: nginx
X-Served: Nginx-Sendfile
X-Deity: web01
Strict-Transport-Security: max-age=1800; includeSubDomains
Date: Mon, 29 Apr 2019 07:59:21 GMT
```

To fix this, we have to serve this file directly from Django instead of using this header.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `readthedocs/core/views/__init__.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 """
4 Core views, including the main homepage,
5 
6 documentation and header rendering, and server errors.
7 """
8 
9 import os
10 import logging
11 from urllib.parse import urlparse
12 
13 from django.conf import settings
14 from django.http import HttpResponseRedirect, Http404, JsonResponse
15 from django.shortcuts import render, get_object_or_404, redirect
16 from django.views.generic import TemplateView
17 
18 
19 from readthedocs.builds.models import Version
20 from readthedocs.core.utils.general import wipe_version_via_slugs
21 from readthedocs.core.resolver import resolve_path
22 from readthedocs.core.symlink import PrivateSymlink, PublicSymlink
23 from readthedocs.core.views.serve import _serve_file
24 from readthedocs.projects.constants import PRIVATE
25 from readthedocs.projects.models import HTMLFile, Project
26 from readthedocs.redirects.utils import (
27     get_redirect_response,
28     project_and_path_from_request,
29     language_and_version_from_path
30 )
31 
32 log = logging.getLogger(__name__)
33 
34 
35 class NoProjectException(Exception):
36     pass
37 
38 
39 class HomepageView(TemplateView):
40 
41     template_name = 'homepage.html'
42 
43     def get_context_data(self, **kwargs):
44         """Add latest builds and featured projects."""
45         context = super().get_context_data(**kwargs)
46         context['featured_list'] = Project.objects.filter(featured=True)
47         context['projects_count'] = Project.objects.count()
48         return context
49 
50 
51 class SupportView(TemplateView):
52     template_name = 'support.html'
53 
54     def get_context_data(self, **kwargs):
55         context = super().get_context_data(**kwargs)
56         support_email = settings.SUPPORT_EMAIL
57         if not support_email:
58             support_email = 'support@{domain}'.format(
59                 domain=settings.PRODUCTION_DOMAIN
60             )
61 
62         context['support_email'] = support_email
63         return context
64 
65 
66 def random_page(request, project_slug=None):  # pylint: disable=unused-argument
67     html_file = HTMLFile.objects.order_by('?')
68     if project_slug:
69         html_file = html_file.filter(project__slug=project_slug)
70     html_file = html_file.first()
71     if html_file is None:
72         raise Http404
73     url = html_file.get_absolute_url()
74     return HttpResponseRedirect(url)
75 
76 
77 def wipe_version(request, project_slug, version_slug):
78     version = get_object_or_404(
79         Version,
80         project__slug=project_slug,
81         slug=version_slug,
82     )
83     # We need to check by ``for_admin_user`` here to allow members of the
84     # ``Admin`` team (which doesn't own the project) under the corporate site.
85     if version.project not in Project.objects.for_admin_user(user=request.user):
86         raise Http404('You must own this project to wipe it.')
87 
88     if request.method == 'POST':
89         wipe_version_via_slugs(
90             version_slug=version_slug,
91             project_slug=project_slug
92         )
93         return redirect('project_version_list', project_slug)
94     return render(
95         request,
96         'wipe_version.html',
97         {'version': version, 'project': version.project},
98     )
99 
100 
101 def server_error_500(request, template_name='500.html'):
102     """A simple 500 handler so we get media."""
103     r = render(request, template_name)
104     r.status_code = 500
105     return r
106 
107 
108 def server_error_404(request, exception=None, template_name='404.html'):  # pylint: disable=unused-argument  # noqa
109     """
110     A simple 404 handler so we get media.
111 
112     .. note::
113 
114         Marking exception as optional to make /404/ testing page to work.
115     """
116     response = get_redirect_response(request, full_path=request.get_full_path())
117 
118     # Return a redirect response if there is one
119     if response:
120         if response.url == request.build_absolute_uri():
121             # check that we do have a response and avoid infinite redirect
122             log.warning(
123                 'Infinite Redirect: FROM URL is the same than TO URL. url=%s',
124                 response.url,
125             )
126         else:
127             return response
128 
129     # Try to serve custom 404 pages if it's a subdomain/cname
130     if getattr(request, 'subdomain', False) or getattr(request, 'cname', False):
131         return server_error_404_subdomain(request, template_name)
132 
133     # Return the default 404 page generated by Read the Docs
134     r = render(request, template_name)
135     r.status_code = 404
136     return r
137 
138 
139 def server_error_404_subdomain(request, template_name='404.html'):
140     """
141     Handler for 404 pages on subdomains.
142 
143     Check if the project associated has a custom ``404.html`` and serve this
144     page. First search for a 404 page in the current version, then continues
145     with the default version and finally, if none of them are found, the Read
146     the Docs default page (Maze Found) is rendered by Django and served.
147     """
148 
149     def resolve_404_path(project, version_slug=None, language=None):
150         """
151         Helper to resolve the path of ``404.html`` for project.
152 
153         The resolution is based on ``project`` object, version slug and
154         language.
155 
156         :returns: tuple containing the (basepath, filename)
157         :rtype: tuple
158         """
159         filename = resolve_path(
160             project,
161             version_slug=version_slug,
162             language=language,
163             filename='404.html',
164             subdomain=True,  # subdomain will make it a "full" path without a URL prefix
165         )
166 
167         # This breaks path joining, by ignoring the root when given an "absolute" path
168         if filename[0] == '/':
169             filename = filename[1:]
170 
171         version = None
172         if version_slug:
173             version_qs = project.versions.filter(slug=version_slug)
174             if version_qs.exists():
175                 version = version_qs.first()
176 
177         private = any([
178             version and version.privacy_level == PRIVATE,
179             not version and project.privacy_level == PRIVATE,
180         ])
181         if private:
182             symlink = PrivateSymlink(project)
183         else:
184             symlink = PublicSymlink(project)
185         basepath = symlink.project_root
186         fullpath = os.path.join(basepath, filename)
187         return (basepath, filename, fullpath)
188 
189     project, full_path = project_and_path_from_request(request, request.get_full_path())
190 
191     if project:
192         language = None
193         version_slug = None
194         schema, netloc, path, params, query, fragments = urlparse(full_path)
195         if not project.single_version:
196             language, version_slug, path = language_and_version_from_path(path)
197 
198         # Firstly, attempt to serve the 404 of the current version (version_slug)
199         # Secondly, try to serve the 404 page for the default version (project.get_default_version())
200         for slug in (version_slug, project.get_default_version()):
201             basepath, filename, fullpath = resolve_404_path(project, slug, language)
202             if os.path.exists(fullpath):
203                 log.debug(
204                     'serving 404.html page current version: [project: %s] [version: %s]',
205                     project.slug,
206                     slug,
207                 )
208                 r = _serve_file(request, filename, basepath)
209                 r.status_code = 404
210                 return r
211 
212     # Finally, return the default 404 page generated by Read the Docs
213     r = render(request, template_name)
214     r.status_code = 404
215     return r
216 
217 
218 def do_not_track(request):
219     dnt_header = request.META.get('HTTP_DNT')
220 
221     # https://w3c.github.io/dnt/drafts/tracking-dnt.html#status-representation
222     return JsonResponse(  # pylint: disable=redundant-content-type-for-json-response
223         {
224             'policy': 'https://docs.readthedocs.io/en/latest/privacy-policy.html',
225             'same-party': [
226                 'readthedocs.org',
227                 'readthedocs.com',
228                 'readthedocs.io',           # .org Documentation Sites
229                 'readthedocs-hosted.com',   # .com Documentation Sites
230             ],
231             'tracking': 'N' if dnt_header == '1' else 'T',
232         }, content_type='application/tracking-status+json',
233     )
234
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py
--- a/readthedocs/core/views/__init__.py
+++ b/readthedocs/core/views/__init__.py
@@ -14,13 +14,12 @@
 from django.http import HttpResponseRedirect, Http404, JsonResponse
 from django.shortcuts import render, get_object_or_404, redirect
 from django.views.generic import TemplateView
-
+from django.views.static import serve as static_serve
 
 from readthedocs.builds.models import Version
 from readthedocs.core.utils.general import wipe_version_via_slugs
 from readthedocs.core.resolver import resolve_path
 from readthedocs.core.symlink import PrivateSymlink, PublicSymlink
-from readthedocs.core.views.serve import _serve_file
 from readthedocs.projects.constants import PRIVATE
 from readthedocs.projects.models import HTMLFile, Project
 from readthedocs.redirects.utils import (
@@ -205,7 +204,7 @@
                     project.slug,
                     slug,
                 )
-                r = _serve_file(request, filename, basepath)
+                r = static_serve(request, filename, basepath)
                 r.status_code = 404
                 return r

{"golden_diff": "diff --git a/readthedocs/core/views/__init__.py b/readthedocs/core/views/__init__.py\n--- a/readthedocs/core/views/__init__.py\n+++ b/readthedocs/core/views/__init__.py\n@@ -14,13 +14,12 @@\n from django.http import HttpResponseRedirect, Http404, JsonResponse\n from django.shortcuts import render, get_object_or_404, redirect\n from django.views.generic import TemplateView\n-\n+from django.views.static import serve as static_serve\n \n from readthedocs.builds.models import Version\n from readthedocs.core.utils.general import wipe_version_via_slugs\n from readthedocs.core.resolver import resolve_path\n from readthedocs.core.symlink import PrivateSymlink, PublicSymlink\n-from readthedocs.core.views.serve import _serve_file\n from readthedocs.projects.constants import PRIVATE\n from readthedocs.projects.models import HTMLFile, Project\n from readthedocs.redirects.utils import (\n@@ -205,7 +204,7 @@\n                     project.slug,\n                     slug,\n                 )\n-                r = _serve_file(request, filename, basepath)\n+                r = static_serve(request, filename, basepath)\n                 r.status_code = 404\n                 return r\n", "issue": "Serve custom 404 pages from Django\nCurrently, we are serving the `404.html` from NGINX returning a `Response` that includes the `X-Accel-Redirect` header:\r\n\r\nhttps://github.com/rtfd/readthedocs.org/blob/537f7b8d2e8d81f8243d1d4a562968e472bc6337/readthedocs/core/views/__init__.py#L208-L210\r\n\r\nWe found that even marking the `response.status_code = 404`, the response is 200.\r\n\r\n```\r\n$ curl -IL https://docs.readthedocs.io/notfound\r\nHTTP/1.1 200 OK\r\nContent-Length: 14167\r\nContent-Type: text/html\r\nLast-Modified: Mon, 22 Apr 2019 15:30:57 GMT\r\nAccept-Ranges: bytes\r\nETag: \"5cbdde31-3757\"\r\nVary: Accept-Encoding\r\nServer: nginx\r\nX-Served: Nginx-Sendfile\r\nX-Deity: web01\r\nStrict-Transport-Security: max-age=1800; includeSubDomains\r\nDate: Mon, 29 Apr 2019 07:59:21 GMT\r\n```\r\n\r\nTo fix this, we have to serve this file directly from Django instead of using this header.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\nCore views, including the main homepage,\n\ndocumentation and header rendering, and server errors.\n\"\"\"\n\nimport os\nimport logging\nfrom urllib.parse import urlparse\n\nfrom django.conf import settings\nfrom django.http import HttpResponseRedirect, Http404, JsonResponse\nfrom django.shortcuts import render, get_object_or_404, redirect\nfrom django.views.generic import TemplateView\n\n\nfrom readthedocs.builds.models import Version\nfrom readthedocs.core.utils.general import wipe_version_via_slugs\nfrom readthedocs.core.resolver import resolve_path\nfrom readthedocs.core.symlink import PrivateSymlink, PublicSymlink\nfrom readthedocs.core.views.serve import _serve_file\nfrom readthedocs.projects.constants import PRIVATE\nfrom readthedocs.projects.models import HTMLFile, Project\nfrom readthedocs.redirects.utils import (\n    get_redirect_response,\n    project_and_path_from_request,\n    language_and_version_from_path\n)\n\nlog = logging.getLogger(__name__)\n\n\nclass NoProjectException(Exception):\n    pass\n\n\nclass HomepageView(TemplateView):\n\n    template_name = 'homepage.html'\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Add latest builds and featured projects.\"\"\"\n        context = super().get_context_data(**kwargs)\n        context['featured_list'] = Project.objects.filter(featured=True)\n        context['projects_count'] = Project.objects.count()\n        return context\n\n\nclass SupportView(TemplateView):\n    template_name = 'support.html'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        support_email = settings.SUPPORT_EMAIL\n        if not support_email:\n            support_email = 'support@{domain}'.format(\n                domain=settings.PRODUCTION_DOMAIN\n            )\n\n        context['support_email'] = support_email\n        return context\n\n\ndef random_page(request, project_slug=None):  # pylint: disable=unused-argument\n    html_file = HTMLFile.objects.order_by('?')\n    if project_slug:\n        html_file = html_file.filter(project__slug=project_slug)\n    html_file = html_file.first()\n    if html_file is None:\n        raise Http404\n    url = html_file.get_absolute_url()\n    return HttpResponseRedirect(url)\n\n\ndef wipe_version(request, project_slug, version_slug):\n    version = get_object_or_404(\n        Version,\n        project__slug=project_slug,\n        slug=version_slug,\n    )\n    # We need to check by ``for_admin_user`` here to allow members of the\n    # ``Admin`` team (which doesn't own the project) under the corporate site.\n    if version.project not in Project.objects.for_admin_user(user=request.user):\n        raise Http404('You must own this project to wipe it.')\n\n    if request.method == 'POST':\n        wipe_version_via_slugs(\n            version_slug=version_slug,\n            project_slug=project_slug\n        )\n        return redirect('project_version_list', project_slug)\n    return render(\n        request,\n        'wipe_version.html',\n        {'version': version, 'project': version.project},\n    )\n\n\ndef server_error_500(request, template_name='500.html'):\n    \"\"\"A simple 500 handler so we get media.\"\"\"\n    r = render(request, template_name)\n    r.status_code = 500\n    return r\n\n\ndef server_error_404(request, exception=None, template_name='404.html'):  # pylint: disable=unused-argument  # noqa\n    \"\"\"\n    A simple 404 handler so we get media.\n\n    .. note::\n\n        Marking exception as optional to make /404/ testing page to work.\n    \"\"\"\n    response = get_redirect_response(request, full_path=request.get_full_path())\n\n    # Return a redirect response if there is one\n    if response:\n        if response.url == request.build_absolute_uri():\n            # check that we do have a response and avoid infinite redirect\n            log.warning(\n                'Infinite Redirect: FROM URL is the same than TO URL. url=%s',\n                response.url,\n            )\n        else:\n            return response\n\n    # Try to serve custom 404 pages if it's a subdomain/cname\n    if getattr(request, 'subdomain', False) or getattr(request, 'cname', False):\n        return server_error_404_subdomain(request, template_name)\n\n    # Return the default 404 page generated by Read the Docs\n    r = render(request, template_name)\n    r.status_code = 404\n    return r\n\n\ndef server_error_404_subdomain(request, template_name='404.html'):\n    \"\"\"\n    Handler for 404 pages on subdomains.\n\n    Check if the project associated has a custom ``404.html`` and serve this\n    page. First search for a 404 page in the current version, then continues\n    with the default version and finally, if none of them are found, the Read\n    the Docs default page (Maze Found) is rendered by Django and served.\n    \"\"\"\n\n    def resolve_404_path(project, version_slug=None, language=None):\n        \"\"\"\n        Helper to resolve the path of ``404.html`` for project.\n\n        The resolution is based on ``project`` object, version slug and\n        language.\n\n        :returns: tuple containing the (basepath, filename)\n        :rtype: tuple\n        \"\"\"\n        filename = resolve_path(\n            project,\n            version_slug=version_slug,\n            language=language,\n            filename='404.html',\n            subdomain=True,  # subdomain will make it a \"full\" path without a URL prefix\n        )\n\n        # This breaks path joining, by ignoring the root when given an \"absolute\" path\n        if filename[0] == '/':\n            filename = filename[1:]\n\n        version = None\n        if version_slug:\n            version_qs = project.versions.filter(slug=version_slug)\n            if version_qs.exists():\n                version = version_qs.first()\n\n        private = any([\n            version and version.privacy_level == PRIVATE,\n            not version and project.privacy_level == PRIVATE,\n        ])\n        if private:\n            symlink = PrivateSymlink(project)\n        else:\n            symlink = PublicSymlink(project)\n        basepath = symlink.project_root\n        fullpath = os.path.join(basepath, filename)\n        return (basepath, filename, fullpath)\n\n    project, full_path = project_and_path_from_request(request, request.get_full_path())\n\n    if project:\n        language = None\n        version_slug = None\n        schema, netloc, path, params, query, fragments = urlparse(full_path)\n        if not project.single_version:\n            language, version_slug, path = language_and_version_from_path(path)\n\n        # Firstly, attempt to serve the 404 of the current version (version_slug)\n        # Secondly, try to serve the 404 page for the default version (project.get_default_version())\n        for slug in (version_slug, project.get_default_version()):\n            basepath, filename, fullpath = resolve_404_path(project, slug, language)\n            if os.path.exists(fullpath):\n                log.debug(\n                    'serving 404.html page current version: [project: %s] [version: %s]',\n                    project.slug,\n                    slug,\n                )\n                r = _serve_file(request, filename, basepath)\n                r.status_code = 404\n                return r\n\n    # Finally, return the default 404 page generated by Read the Docs\n    r = render(request, template_name)\n    r.status_code = 404\n    return r\n\n\ndef do_not_track(request):\n    dnt_header = request.META.get('HTTP_DNT')\n\n    # https://w3c.github.io/dnt/drafts/tracking-dnt.html#status-representation\n    return JsonResponse(  # pylint: disable=redundant-content-type-for-json-response\n        {\n            'policy': 'https://docs.readthedocs.io/en/latest/privacy-policy.html',\n            'same-party': [\n                'readthedocs.org',\n                'readthedocs.com',\n                'readthedocs.io',           # .org Documentation Sites\n                'readthedocs-hosted.com',   # .com Documentation Sites\n            ],\n            'tracking': 'N' if dnt_header == '1' else 'T',\n        }, content_type='application/tracking-status+json',\n    )\n", "path": "readthedocs/core/views/__init__.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\nCore views, including the main homepage,\n\ndocumentation and header rendering, and server errors.\n\"\"\"\n\nimport os\nimport logging\nfrom urllib.parse import urlparse\n\nfrom django.conf import settings\nfrom django.http import HttpResponseRedirect, Http404, JsonResponse\nfrom django.shortcuts import render, get_object_or_404, redirect\nfrom django.views.generic import TemplateView\nfrom django.views.static import serve as static_serve\n\nfrom readthedocs.builds.models import Version\nfrom readthedocs.core.utils.general import wipe_version_via_slugs\nfrom readthedocs.core.resolver import resolve_path\nfrom readthedocs.core.symlink import PrivateSymlink, PublicSymlink\nfrom readthedocs.projects.constants import PRIVATE\nfrom readthedocs.projects.models import HTMLFile, Project\nfrom readthedocs.redirects.utils import (\n    get_redirect_response,\n    project_and_path_from_request,\n    language_and_version_from_path\n)\n\nlog = logging.getLogger(__name__)\n\n\nclass NoProjectException(Exception):\n    pass\n\n\nclass HomepageView(TemplateView):\n\n    template_name = 'homepage.html'\n\n    def get_context_data(self, **kwargs):\n        \"\"\"Add latest builds and featured projects.\"\"\"\n        context = super().get_context_data(**kwargs)\n        context['featured_list'] = Project.objects.filter(featured=True)\n        context['projects_count'] = Project.objects.count()\n        return context\n\n\nclass SupportView(TemplateView):\n    template_name = 'support.html'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        support_email = settings.SUPPORT_EMAIL\n        if not support_email:\n            support_email = 'support@{domain}'.format(\n                domain=settings.PRODUCTION_DOMAIN\n            )\n\n        context['support_email'] = support_email\n        return context\n\n\ndef random_page(request, project_slug=None):  # pylint: disable=unused-argument\n    html_file = HTMLFile.objects.order_by('?')\n    if project_slug:\n        html_file = html_file.filter(project__slug=project_slug)\n    html_file = html_file.first()\n    if html_file is None:\n        raise Http404\n    url = html_file.get_absolute_url()\n    return HttpResponseRedirect(url)\n\n\ndef wipe_version(request, project_slug, version_slug):\n    version = get_object_or_404(\n        Version,\n        project__slug=project_slug,\n        slug=version_slug,\n    )\n    # We need to check by ``for_admin_user`` here to allow members of the\n    # ``Admin`` team (which doesn't own the project) under the corporate site.\n    if version.project not in Project.objects.for_admin_user(user=request.user):\n        raise Http404('You must own this project to wipe it.')\n\n    if request.method == 'POST':\n        wipe_version_via_slugs(\n            version_slug=version_slug,\n            project_slug=project_slug\n        )\n        return redirect('project_version_list', project_slug)\n    return render(\n        request,\n        'wipe_version.html',\n        {'version': version, 'project': version.project},\n    )\n\n\ndef server_error_500(request, template_name='500.html'):\n    \"\"\"A simple 500 handler so we get media.\"\"\"\n    r = render(request, template_name)\n    r.status_code = 500\n    return r\n\n\ndef server_error_404(request, exception=None, template_name='404.html'):  # pylint: disable=unused-argument  # noqa\n    \"\"\"\n    A simple 404 handler so we get media.\n\n    .. note::\n\n        Marking exception as optional to make /404/ testing page to work.\n    \"\"\"\n    response = get_redirect_response(request, full_path=request.get_full_path())\n\n    # Return a redirect response if there is one\n    if response:\n        if response.url == request.build_absolute_uri():\n            # check that we do have a response and avoid infinite redirect\n            log.warning(\n                'Infinite Redirect: FROM URL is the same than TO URL. url=%s',\n                response.url,\n            )\n        else:\n            return response\n\n    # Try to serve custom 404 pages if it's a subdomain/cname\n    if getattr(request, 'subdomain', False) or getattr(request, 'cname', False):\n        return server_error_404_subdomain(request, template_name)\n\n    # Return the default 404 page generated by Read the Docs\n    r = render(request, template_name)\n    r.status_code = 404\n    return r\n\n\ndef server_error_404_subdomain(request, template_name='404.html'):\n    \"\"\"\n    Handler for 404 pages on subdomains.\n\n    Check if the project associated has a custom ``404.html`` and serve this\n    page. First search for a 404 page in the current version, then continues\n    with the default version and finally, if none of them are found, the Read\n    the Docs default page (Maze Found) is rendered by Django and served.\n    \"\"\"\n\n    def resolve_404_path(project, version_slug=None, language=None):\n        \"\"\"\n        Helper to resolve the path of ``404.html`` for project.\n\n        The resolution is based on ``project`` object, version slug and\n        language.\n\n        :returns: tuple containing the (basepath, filename)\n        :rtype: tuple\n        \"\"\"\n        filename = resolve_path(\n            project,\n            version_slug=version_slug,\n            language=language,\n            filename='404.html',\n            subdomain=True,  # subdomain will make it a \"full\" path without a URL prefix\n        )\n\n        # This breaks path joining, by ignoring the root when given an \"absolute\" path\n        if filename[0] == '/':\n            filename = filename[1:]\n\n        version = None\n        if version_slug:\n            version_qs = project.versions.filter(slug=version_slug)\n            if version_qs.exists():\n                version = version_qs.first()\n\n        private = any([\n            version and version.privacy_level == PRIVATE,\n            not version and project.privacy_level == PRIVATE,\n        ])\n        if private:\n            symlink = PrivateSymlink(project)\n        else:\n            symlink = PublicSymlink(project)\n        basepath = symlink.project_root\n        fullpath = os.path.join(basepath, filename)\n        return (basepath, filename, fullpath)\n\n    project, full_path = project_and_path_from_request(request, request.get_full_path())\n\n    if project:\n        language = None\n        version_slug = None\n        schema, netloc, path, params, query, fragments = urlparse(full_path)\n        if not project.single_version:\n            language, version_slug, path = language_and_version_from_path(path)\n\n        # Firstly, attempt to serve the 404 of the current version (version_slug)\n        # Secondly, try to serve the 404 page for the default version (project.get_default_version())\n        for slug in (version_slug, project.get_default_version()):\n            basepath, filename, fullpath = resolve_404_path(project, slug, language)\n            if os.path.exists(fullpath):\n                log.debug(\n                    'serving 404.html page current version: [project: %s] [version: %s]',\n                    project.slug,\n                    slug,\n                )\n                r = static_serve(request, filename, basepath)\n                r.status_code = 404\n                return r\n\n    # Finally, return the default 404 page generated by Read the Docs\n    r = render(request, template_name)\n    r.status_code = 404\n    return r\n\n\ndef do_not_track(request):\n    dnt_header = request.META.get('HTTP_DNT')\n\n    # https://w3c.github.io/dnt/drafts/tracking-dnt.html#status-representation\n    return JsonResponse(  # pylint: disable=redundant-content-type-for-json-response\n        {\n            'policy': 'https://docs.readthedocs.io/en/latest/privacy-policy.html',\n            'same-party': [\n                'readthedocs.org',\n                'readthedocs.com',\n                'readthedocs.io',           # .org Documentation Sites\n                'readthedocs-hosted.com',   # .com Documentation Sites\n            ],\n            'tracking': 'N' if dnt_header == '1' else 'T',\n        }, content_type='application/tracking-status+json',\n    )\n", "path": "readthedocs/core/views/__init__.py"}]}