Changeset - da121e5eb4d4
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 months ago 2024-03-21 23:10:57
ben@sturm.com.au
Specify encoding for templates in case it's not the default
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy/views.py
Show inline comments
...
 
@@ -39,16 +39,16 @@ def index(request, *args, **kwargs):
 
    elif not full_path.exists() or not safe_from_path_traversal:
 
        raise Http404()
 
    is_template = mimetypes.guess_type(full_path)[0] == 'text/html'
 
    if not is_template:
 
        return FileResponse(open(full_path, 'rb'))
 
    else:
 
        try:
 
            kwargs['fundgoal'] = fundgoal_lookup(kwargs['fundraiser_sought'])
 
        except KeyError:
 
            pass
 
        # 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:
 
        with open(full_path, encoding='utf-8') as t:
 
            template = Template(t.read())
 
        context = RequestContext(request, kwargs)
 
        return HttpResponse(template.render(context))
0 comments (0 inline, 0 general)