We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SuspiciousOperation in asset_proxy URLs
Since switching our site from HTTP to HTTPS, I've been getting the following error on all of TinyMCE's dialog windows.

```
SuspiciousOperation: Attempted access to '/static/grappelli/tinymce/jscripts/tiny_mce/themes/advanced/source_editor.htm' denied.

Stacktrace (most recent call last):

  File "django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "django/contrib/admin/views/decorators.py", line 17, in _checklogin
    return view_func(request, *args, **kwargs)
  File "mezzanine/core/views.py", line 143, in static_proxy
    path = finders.find(url)
  File "django/contrib/staticfiles/finders.py", line 239, in find
    result = finder.find(path, all=all)
  File "django/contrib/staticfiles/finders.py", line 147, in find
    match = self.find_in_app(app, path)
  File "django/contrib/staticfiles/finders.py", line 166, in find_in_app
    if storage.exists(path):
  File "django/core/files/storage.py", line 243, in exists
    return os.path.exists(self.path(name))
  File "django/core/files/storage.py", line 259, in path
    raise SuspiciousOperation("Attempted access to '%s' denied." % name)
```

The URLs that are causing them look like this:

```
https://www.example.com/asset_proxy/?u=https://www.example.com/static/grappelli/tinymce/jscripts/tiny_mce/themes/advanced/source_editor.htm
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mezzanine/core/views.py`
Content:
```
1 import os
2 from urlparse import urljoin, urlparse
3 
4 from django.contrib import admin
5 from django.contrib.admin.views.decorators import staff_member_required
6 from django.contrib.admin.options import ModelAdmin
7 from django.contrib.staticfiles import finders
8 from django.core.exceptions import PermissionDenied
9 from django.core.urlresolvers import reverse
10 from django.db.models import get_model
11 from django.http import (HttpResponse, HttpResponseServerError,
12                          HttpResponseNotFound)
13 from django.shortcuts import redirect
14 from django.template import RequestContext
15 from django.template.loader import get_template
16 from django.utils.translation import ugettext_lazy as _
17 from django.views.decorators.csrf import requires_csrf_token
18 
19 from mezzanine.conf import settings
20 from mezzanine.core.forms import get_edit_form
21 from mezzanine.core.models import Displayable, SitePermission
22 from mezzanine.utils.cache import add_cache_bypass
23 from mezzanine.utils.views import is_editable, paginate, render, set_cookie
24 from mezzanine.utils.sites import has_site_permission
25 
26 
27 def set_device(request, device=""):
28     """
29     Sets a device name in a cookie when a user explicitly wants to go
30     to the site for a particular device (eg mobile).
31     """
32     response = redirect(add_cache_bypass(request.GET.get("next") or "/"))
33     set_cookie(response, "mezzanine-device", device, 60 * 60 * 24 * 365)
34     return response
35 
36 
37 @staff_member_required
38 def set_site(request):
39     """
40     Put the selected site ID into the session - posted to from
41     the "Select site" drop-down in the header of the admin. The
42     site ID is then used in favour of the current request's
43     domain in ``mezzanine.core.managers.CurrentSiteManager``.
44     """
45     site_id = int(request.GET["site_id"])
46     if not request.user.is_superuser:
47         try:
48             SitePermission.objects.get(user=request.user, sites=site_id)
49         except SitePermission.DoesNotExist:
50             raise PermissionDenied
51     request.session["site_id"] = site_id
52     admin_url = reverse("admin:index")
53     next = request.GET.get("next") or admin_url
54     # Don't redirect to a change view for an object that won't exist
55     # on the selected site - go to its list view instead.
56     if next.startswith(admin_url):
57         parts = next.split("/")
58         if len(parts) > 4 and parts[4].isdigit():
59             next = "/".join(parts[:4])
60     return redirect(next)
61 
62 
63 def direct_to_template(request, template, extra_context=None, **kwargs):
64     """
65     Replacement for Django's ``direct_to_template`` that uses
66     ``TemplateResponse`` via ``mezzanine.utils.views.render``.
67     """
68     context = extra_context or {}
69     context["params"] = kwargs
70     for (key, value) in context.items():
71         if callable(value):
72             context[key] = value()
73     return render(request, template, context)
74 
75 
76 @staff_member_required
77 def edit(request):
78     """
79     Process the inline editing form.
80     """
81     model = get_model(request.POST["app"], request.POST["model"])
82     obj = model.objects.get(id=request.POST["id"])
83     form = get_edit_form(obj, request.POST["fields"], data=request.POST,
84                          files=request.FILES)
85     if not (is_editable(obj, request) and has_site_permission(request.user)):
86         response = _("Permission denied")
87     elif form.is_valid():
88         form.save()
89         model_admin = ModelAdmin(model, admin.site)
90         message = model_admin.construct_change_message(request, form, None)
91         model_admin.log_change(request, obj, message)
92         response = ""
93     else:
94         response = form.errors.values()[0][0]
95     return HttpResponse(unicode(response))
96 
97 
98 def search(request, template="search_results.html"):
99     """
100     Display search results. Takes an optional "contenttype" GET parameter
101     in the form "app-name.ModelName" to limit search results to a single model.
102     """
103     settings.use_editable()
104     query = request.GET.get("q", "")
105     page = request.GET.get("page", 1)
106     per_page = settings.SEARCH_PER_PAGE
107     max_paging_links = settings.MAX_PAGING_LINKS
108     try:
109         search_model = get_model(*request.GET.get("type", "").split(".", 1))
110         if not issubclass(search_model, Displayable):
111             raise TypeError
112     except TypeError:
113         search_model = Displayable
114         search_type = _("Everything")
115     else:
116         search_type = search_model._meta.verbose_name_plural.capitalize()
117     results = search_model.objects.search(query, for_user=request.user)
118     paginated = paginate(results, page, per_page, max_paging_links)
119     context = {"query": query, "results": paginated,
120                "search_type": search_type}
121     return render(request, template, context)
122 
123 
124 @staff_member_required
125 def static_proxy(request):
126     """
127     Serves TinyMCE plugins inside the inline popups and the uploadify
128     SWF, as these are normally static files, and will break with
129     cross-domain JavaScript errors if ``STATIC_URL`` is an external
130     host. URL for the file is passed in via querystring in the inline
131     popup plugin template.
132     """
133     # Get the relative URL after STATIC_URL.
134     url = request.GET["u"]
135     protocol = "http" if not request.is_secure() else "https"
136     host = protocol + "://" + request.get_host()
137     generic_host = "//" + request.get_host()
138     for prefix in (host, generic_host, settings.STATIC_URL):
139         if url.startswith(prefix):
140             url = url.replace(prefix, "", 1)
141     response = ""
142     mimetype = ""
143     path = finders.find(url)
144     if path:
145         if isinstance(path, (list, tuple)):
146             path = path[0]
147         with open(path, "rb") as f:
148             response = f.read()
149         mimetype = "application/octet-stream"
150         if url.endswith(".htm"):
151             # Inject <base href="{{ STATIC_URL }}"> into TinyMCE
152             # plugins, since the path static files in these won't be
153             # on the same domain.
154             mimetype = "text/html"
155             static_url = settings.STATIC_URL + os.path.split(url)[0] + "/"
156             if not urlparse(static_url).scheme:
157                 static_url = urljoin(host, static_url)
158             base_tag = "<base href='%s'>" % static_url
159             response = response.replace("<head>", "<head>" + base_tag)
160     return HttpResponse(response, mimetype=mimetype)
161 
162 
163 @requires_csrf_token
164 def page_not_found(request, template_name="errors/404.html"):
165     """
166     Mimics Django's 404 handler but with a different template path.
167     """
168     context = RequestContext(request, {
169         "STATIC_URL": settings.STATIC_URL,
170         "request_path": request.path,
171     })
172     t = get_template(template_name)
173     return HttpResponseNotFound(t.render(context))
174 
175 
176 @requires_csrf_token
177 def server_error(request, template_name="errors/500.html"):
178     """
179     Mimics Django's error handler but adds ``STATIC_URL`` to the
180     context.
181     """
182     context = RequestContext(request, {"STATIC_URL": settings.STATIC_URL})
183     t = get_template(template_name)
184     return HttpResponseServerError(t.render(context))
185
```
--- 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/mezzanine/core/views.py b/mezzanine/core/views.py
--- a/mezzanine/core/views.py
+++ b/mezzanine/core/views.py
@@ -135,7 +135,7 @@
     protocol = "http" if not request.is_secure() else "https"
     host = protocol + "://" + request.get_host()
     generic_host = "//" + request.get_host()
-    for prefix in (host, generic_host, settings.STATIC_URL):
+    for prefix in (settings.STATIC_URL, host, generic_host, '/'):
         if url.startswith(prefix):
             url = url.replace(prefix, "", 1)
     response = ""

{"golden_diff": "diff --git a/mezzanine/core/views.py b/mezzanine/core/views.py\n--- a/mezzanine/core/views.py\n+++ b/mezzanine/core/views.py\n@@ -135,7 +135,7 @@\n     protocol = \"http\" if not request.is_secure() else \"https\"\n     host = protocol + \"://\" + request.get_host()\n     generic_host = \"//\" + request.get_host()\n-    for prefix in (host, generic_host, settings.STATIC_URL):\n+    for prefix in (settings.STATIC_URL, host, generic_host, '/'):\n         if url.startswith(prefix):\n             url = url.replace(prefix, \"\", 1)\n     response = \"\"\n", "issue": "SuspiciousOperation in asset_proxy URLs\nSince switching our site from HTTP to HTTPS, I've been getting the following error on all of TinyMCE's dialog windows.\n\n```\nSuspiciousOperation: Attempted access to '/static/grappelli/tinymce/jscripts/tiny_mce/themes/advanced/source_editor.htm' denied.\n\nStacktrace (most recent call last):\n\n  File \"django/core/handlers/base.py\", line 115, in get_response\n    response = callback(request, *callback_args, **callback_kwargs)\n  File \"django/contrib/admin/views/decorators.py\", line 17, in _checklogin\n    return view_func(request, *args, **kwargs)\n  File \"mezzanine/core/views.py\", line 143, in static_proxy\n    path = finders.find(url)\n  File \"django/contrib/staticfiles/finders.py\", line 239, in find\n    result = finder.find(path, all=all)\n  File \"django/contrib/staticfiles/finders.py\", line 147, in find\n    match = self.find_in_app(app, path)\n  File \"django/contrib/staticfiles/finders.py\", line 166, in find_in_app\n    if storage.exists(path):\n  File \"django/core/files/storage.py\", line 243, in exists\n    return os.path.exists(self.path(name))\n  File \"django/core/files/storage.py\", line 259, in path\n    raise SuspiciousOperation(\"Attempted access to '%s' denied.\" % name)\n```\n\nThe URLs that are causing them look like this:\n\n```\nhttps://www.example.com/asset_proxy/?u=https://www.example.com/static/grappelli/tinymce/jscripts/tiny_mce/themes/advanced/source_editor.htm\n```\n\n", "before_files": [{"content": "import os\nfrom urlparse import urljoin, urlparse\n\nfrom django.contrib import admin\nfrom django.contrib.admin.views.decorators import staff_member_required\nfrom django.contrib.admin.options import ModelAdmin\nfrom django.contrib.staticfiles import finders\nfrom django.core.exceptions import PermissionDenied\nfrom django.core.urlresolvers import reverse\nfrom django.db.models import get_model\nfrom django.http import (HttpResponse, HttpResponseServerError,\n                         HttpResponseNotFound)\nfrom django.shortcuts import redirect\nfrom django.template import RequestContext\nfrom django.template.loader import get_template\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.decorators.csrf import requires_csrf_token\n\nfrom mezzanine.conf import settings\nfrom mezzanine.core.forms import get_edit_form\nfrom mezzanine.core.models import Displayable, SitePermission\nfrom mezzanine.utils.cache import add_cache_bypass\nfrom mezzanine.utils.views import is_editable, paginate, render, set_cookie\nfrom mezzanine.utils.sites import has_site_permission\n\n\ndef set_device(request, device=\"\"):\n    \"\"\"\n    Sets a device name in a cookie when a user explicitly wants to go\n    to the site for a particular device (eg mobile).\n    \"\"\"\n    response = redirect(add_cache_bypass(request.GET.get(\"next\") or \"/\"))\n    set_cookie(response, \"mezzanine-device\", device, 60 * 60 * 24 * 365)\n    return response\n\n\n@staff_member_required\ndef set_site(request):\n    \"\"\"\n    Put the selected site ID into the session - posted to from\n    the \"Select site\" drop-down in the header of the admin. The\n    site ID is then used in favour of the current request's\n    domain in ``mezzanine.core.managers.CurrentSiteManager``.\n    \"\"\"\n    site_id = int(request.GET[\"site_id\"])\n    if not request.user.is_superuser:\n        try:\n            SitePermission.objects.get(user=request.user, sites=site_id)\n        except SitePermission.DoesNotExist:\n            raise PermissionDenied\n    request.session[\"site_id\"] = site_id\n    admin_url = reverse(\"admin:index\")\n    next = request.GET.get(\"next\") or admin_url\n    # Don't redirect to a change view for an object that won't exist\n    # on the selected site - go to its list view instead.\n    if next.startswith(admin_url):\n        parts = next.split(\"/\")\n        if len(parts) > 4 and parts[4].isdigit():\n            next = \"/\".join(parts[:4])\n    return redirect(next)\n\n\ndef direct_to_template(request, template, extra_context=None, **kwargs):\n    \"\"\"\n    Replacement for Django's ``direct_to_template`` that uses\n    ``TemplateResponse`` via ``mezzanine.utils.views.render``.\n    \"\"\"\n    context = extra_context or {}\n    context[\"params\"] = kwargs\n    for (key, value) in context.items():\n        if callable(value):\n            context[key] = value()\n    return render(request, template, context)\n\n\n@staff_member_required\ndef edit(request):\n    \"\"\"\n    Process the inline editing form.\n    \"\"\"\n    model = get_model(request.POST[\"app\"], request.POST[\"model\"])\n    obj = model.objects.get(id=request.POST[\"id\"])\n    form = get_edit_form(obj, request.POST[\"fields\"], data=request.POST,\n                         files=request.FILES)\n    if not (is_editable(obj, request) and has_site_permission(request.user)):\n        response = _(\"Permission denied\")\n    elif form.is_valid():\n        form.save()\n        model_admin = ModelAdmin(model, admin.site)\n        message = model_admin.construct_change_message(request, form, None)\n        model_admin.log_change(request, obj, message)\n        response = \"\"\n    else:\n        response = form.errors.values()[0][0]\n    return HttpResponse(unicode(response))\n\n\ndef search(request, template=\"search_results.html\"):\n    \"\"\"\n    Display search results. Takes an optional \"contenttype\" GET parameter\n    in the form \"app-name.ModelName\" to limit search results to a single model.\n    \"\"\"\n    settings.use_editable()\n    query = request.GET.get(\"q\", \"\")\n    page = request.GET.get(\"page\", 1)\n    per_page = settings.SEARCH_PER_PAGE\n    max_paging_links = settings.MAX_PAGING_LINKS\n    try:\n        search_model = get_model(*request.GET.get(\"type\", \"\").split(\".\", 1))\n        if not issubclass(search_model, Displayable):\n            raise TypeError\n    except TypeError:\n        search_model = Displayable\n        search_type = _(\"Everything\")\n    else:\n        search_type = search_model._meta.verbose_name_plural.capitalize()\n    results = search_model.objects.search(query, for_user=request.user)\n    paginated = paginate(results, page, per_page, max_paging_links)\n    context = {\"query\": query, \"results\": paginated,\n               \"search_type\": search_type}\n    return render(request, template, context)\n\n\n@staff_member_required\ndef static_proxy(request):\n    \"\"\"\n    Serves TinyMCE plugins inside the inline popups and the uploadify\n    SWF, as these are normally static files, and will break with\n    cross-domain JavaScript errors if ``STATIC_URL`` is an external\n    host. URL for the file is passed in via querystring in the inline\n    popup plugin template.\n    \"\"\"\n    # Get the relative URL after STATIC_URL.\n    url = request.GET[\"u\"]\n    protocol = \"http\" if not request.is_secure() else \"https\"\n    host = protocol + \"://\" + request.get_host()\n    generic_host = \"//\" + request.get_host()\n    for prefix in (host, generic_host, settings.STATIC_URL):\n        if url.startswith(prefix):\n            url = url.replace(prefix, \"\", 1)\n    response = \"\"\n    mimetype = \"\"\n    path = finders.find(url)\n    if path:\n        if isinstance(path, (list, tuple)):\n            path = path[0]\n        with open(path, \"rb\") as f:\n            response = f.read()\n        mimetype = \"application/octet-stream\"\n        if url.endswith(\".htm\"):\n            # Inject <base href=\"{{ STATIC_URL }}\"> into TinyMCE\n            # plugins, since the path static files in these won't be\n            # on the same domain.\n            mimetype = \"text/html\"\n            static_url = settings.STATIC_URL + os.path.split(url)[0] + \"/\"\n            if not urlparse(static_url).scheme:\n                static_url = urljoin(host, static_url)\n            base_tag = \"<base href='%s'>\" % static_url\n            response = response.replace(\"<head>\", \"<head>\" + base_tag)\n    return HttpResponse(response, mimetype=mimetype)\n\n\n@requires_csrf_token\ndef page_not_found(request, template_name=\"errors/404.html\"):\n    \"\"\"\n    Mimics Django's 404 handler but with a different template path.\n    \"\"\"\n    context = RequestContext(request, {\n        \"STATIC_URL\": settings.STATIC_URL,\n        \"request_path\": request.path,\n    })\n    t = get_template(template_name)\n    return HttpResponseNotFound(t.render(context))\n\n\n@requires_csrf_token\ndef server_error(request, template_name=\"errors/500.html\"):\n    \"\"\"\n    Mimics Django's error handler but adds ``STATIC_URL`` to the\n    context.\n    \"\"\"\n    context = RequestContext(request, {\"STATIC_URL\": settings.STATIC_URL})\n    t = get_template(template_name)\n    return HttpResponseServerError(t.render(context))\n", "path": "mezzanine/core/views.py"}], "after_files": [{"content": "import os\nfrom urlparse import urljoin, urlparse\n\nfrom django.contrib import admin\nfrom django.contrib.admin.views.decorators import staff_member_required\nfrom django.contrib.admin.options import ModelAdmin\nfrom django.contrib.staticfiles import finders\nfrom django.core.exceptions import PermissionDenied\nfrom django.core.urlresolvers import reverse\nfrom django.db.models import get_model\nfrom django.http import (HttpResponse, HttpResponseServerError,\n                         HttpResponseNotFound)\nfrom django.shortcuts import redirect\nfrom django.template import RequestContext\nfrom django.template.loader import get_template\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views.decorators.csrf import requires_csrf_token\n\nfrom mezzanine.conf import settings\nfrom mezzanine.core.forms import get_edit_form\nfrom mezzanine.core.models import Displayable, SitePermission\nfrom mezzanine.utils.cache import add_cache_bypass\nfrom mezzanine.utils.views import is_editable, paginate, render, set_cookie\nfrom mezzanine.utils.sites import has_site_permission\n\n\ndef set_device(request, device=\"\"):\n    \"\"\"\n    Sets a device name in a cookie when a user explicitly wants to go\n    to the site for a particular device (eg mobile).\n    \"\"\"\n    response = redirect(add_cache_bypass(request.GET.get(\"next\") or \"/\"))\n    set_cookie(response, \"mezzanine-device\", device, 60 * 60 * 24 * 365)\n    return response\n\n\n@staff_member_required\ndef set_site(request):\n    \"\"\"\n    Put the selected site ID into the session - posted to from\n    the \"Select site\" drop-down in the header of the admin. The\n    site ID is then used in favour of the current request's\n    domain in ``mezzanine.core.managers.CurrentSiteManager``.\n    \"\"\"\n    site_id = int(request.GET[\"site_id\"])\n    if not request.user.is_superuser:\n        try:\n            SitePermission.objects.get(user=request.user, sites=site_id)\n        except SitePermission.DoesNotExist:\n            raise PermissionDenied\n    request.session[\"site_id\"] = site_id\n    admin_url = reverse(\"admin:index\")\n    next = request.GET.get(\"next\") or admin_url\n    # Don't redirect to a change view for an object that won't exist\n    # on the selected site - go to its list view instead.\n    if next.startswith(admin_url):\n        parts = next.split(\"/\")\n        if len(parts) > 4 and parts[4].isdigit():\n            next = \"/\".join(parts[:4])\n    return redirect(next)\n\n\ndef direct_to_template(request, template, extra_context=None, **kwargs):\n    \"\"\"\n    Replacement for Django's ``direct_to_template`` that uses\n    ``TemplateResponse`` via ``mezzanine.utils.views.render``.\n    \"\"\"\n    context = extra_context or {}\n    context[\"params\"] = kwargs\n    for (key, value) in context.items():\n        if callable(value):\n            context[key] = value()\n    return render(request, template, context)\n\n\n@staff_member_required\ndef edit(request):\n    \"\"\"\n    Process the inline editing form.\n    \"\"\"\n    model = get_model(request.POST[\"app\"], request.POST[\"model\"])\n    obj = model.objects.get(id=request.POST[\"id\"])\n    form = get_edit_form(obj, request.POST[\"fields\"], data=request.POST,\n                         files=request.FILES)\n    if not (is_editable(obj, request) and has_site_permission(request.user)):\n        response = _(\"Permission denied\")\n    elif form.is_valid():\n        form.save()\n        model_admin = ModelAdmin(model, admin.site)\n        message = model_admin.construct_change_message(request, form, None)\n        model_admin.log_change(request, obj, message)\n        response = \"\"\n    else:\n        response = form.errors.values()[0][0]\n    return HttpResponse(unicode(response))\n\n\ndef search(request, template=\"search_results.html\"):\n    \"\"\"\n    Display search results. Takes an optional \"contenttype\" GET parameter\n    in the form \"app-name.ModelName\" to limit search results to a single model.\n    \"\"\"\n    settings.use_editable()\n    query = request.GET.get(\"q\", \"\")\n    page = request.GET.get(\"page\", 1)\n    per_page = settings.SEARCH_PER_PAGE\n    max_paging_links = settings.MAX_PAGING_LINKS\n    try:\n        search_model = get_model(*request.GET.get(\"type\", \"\").split(\".\", 1))\n        if not issubclass(search_model, Displayable):\n            raise TypeError\n    except TypeError:\n        search_model = Displayable\n        search_type = _(\"Everything\")\n    else:\n        search_type = search_model._meta.verbose_name_plural.capitalize()\n    results = search_model.objects.search(query, for_user=request.user)\n    paginated = paginate(results, page, per_page, max_paging_links)\n    context = {\"query\": query, \"results\": paginated,\n               \"search_type\": search_type}\n    return render(request, template, context)\n\n\n@staff_member_required\ndef static_proxy(request):\n    \"\"\"\n    Serves TinyMCE plugins inside the inline popups and the uploadify\n    SWF, as these are normally static files, and will break with\n    cross-domain JavaScript errors if ``STATIC_URL`` is an external\n    host. URL for the file is passed in via querystring in the inline\n    popup plugin template.\n    \"\"\"\n    # Get the relative URL after STATIC_URL.\n    url = request.GET[\"u\"]\n    protocol = \"http\" if not request.is_secure() else \"https\"\n    host = protocol + \"://\" + request.get_host()\n    generic_host = \"//\" + request.get_host()\n    for prefix in (settings.STATIC_URL, host, generic_host, '/'):\n        if url.startswith(prefix):\n            url = url.replace(prefix, \"\", 1)\n    response = \"\"\n    mimetype = \"\"\n    path = finders.find(url)\n    if path:\n        if isinstance(path, (list, tuple)):\n            path = path[0]\n        with open(path, \"rb\") as f:\n            response = f.read()\n        mimetype = \"application/octet-stream\"\n        if url.endswith(\".htm\"):\n            # Inject <base href=\"{{ STATIC_URL }}\"> into TinyMCE\n            # plugins, since the path static files in these won't be\n            # on the same domain.\n            mimetype = \"text/html\"\n            static_url = settings.STATIC_URL + os.path.split(url)[0] + \"/\"\n            if not urlparse(static_url).scheme:\n                static_url = urljoin(host, static_url)\n            base_tag = \"<base href='%s'>\" % static_url\n            response = response.replace(\"<head>\", \"<head>\" + base_tag)\n    return HttpResponse(response, mimetype=mimetype)\n\n\n@requires_csrf_token\ndef page_not_found(request, template_name=\"errors/404.html\"):\n    \"\"\"\n    Mimics Django's 404 handler but with a different template path.\n    \"\"\"\n    context = RequestContext(request, {\n        \"STATIC_URL\": settings.STATIC_URL,\n        \"request_path\": request.path,\n    })\n    t = get_template(template_name)\n    return HttpResponseNotFound(t.render(context))\n\n\n@requires_csrf_token\ndef server_error(request, template_name=\"errors/500.html\"):\n    \"\"\"\n    Mimics Django's error handler but adds ``STATIC_URL`` to the\n    context.\n    \"\"\"\n    context = RequestContext(request, {\"STATIC_URL\": settings.STATIC_URL})\n    t = get_template(template_name)\n    return HttpResponseServerError(t.render(context))\n", "path": "mezzanine/core/views.py"}]}