diff --git a/conservancy/views.py b/conservancy/views.py index 21059710f9d131c2ca22a827bf4026c079f418a5..560eaf61f9b0b75728fc9a41332e989c5c42f00f 100644 --- a/conservancy/views.py +++ b/conservancy/views.py @@ -1,8 +1,8 @@ import mimetypes from django.conf import settings -from django.http import FileResponse, Http404, HttpResponseRedirect -from django.template.response import TemplateResponse +from django.http import FileResponse, Http404, HttpResponse, HttpResponseRedirect +from django.template import RequestContext, Template from .local_context_processors import fundgoal_lookup @@ -27,8 +27,7 @@ def index(request, *args, **kwargs): infrastructure. If it finds a file but it's not a template, it will serve the file as-is. """ - # The name "static" has no connection to Django staticfiles. - base_path = settings.BASE_DIR / 'static' + base_path = settings.BASE_DIR / 'content' path = request.path.lstrip('/') if path.endswith('/'): path += 'index.html' @@ -43,11 +42,13 @@ def index(request, *args, **kwargs): if not is_template: return FileResponse(open(full_path, 'rb')) else: - context = kwargs.copy() try: - context['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought']) + kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought']) except KeyError: pass - # Maybe this should open() the template file directly so that these - # don't have to be included in the global template TEMPLATES.DIRS? - return TemplateResponse(request, path, context) + # These template are intentionally not in the template loader path, so + # we open them directly, rather than using the template loader. + with open(full_path) as t: + template = Template(t.read()) + context = RequestContext(request, kwargs) + return HttpResponse(template.render(context))