Skip to content

Instantly share code, notes, and snippets.

@cmc333333
Created September 24, 2014 18:45
Show Gist options
  • Select an option

  • Save cmc333333/365e606f4a9737370fee to your computer and use it in GitHub Desktop.

Select an option

Save cmc333333/365e606f4a9737370fee to your computer and use it in GitHub Desktop.
diff --git a/foia_hub/views.py b/foia_hub/views.py
index 3debba1..e0249b5 100644
--- a/foia_hub/views.py
+++ b/foia_hub/views.py
@@ -9,20 +9,23 @@ from jinja2 import Environment, PackageLoader
from foia_hub.models import Agency, FOIARequest
-env = Environment(loader=PackageLoader('foia_hub', 'templates'))
-env.globals['ANALYTICS_ID'] = settings.ANALYTICS_ID
+def env():
+ """Return a configured jinja2 environment"""
+ env = Environment(loader=PackageLoader('foia_hub', 'templates'))
+ env.globals['ANALYTICS_ID'] = settings.ANALYTICS_ID
+ return env
def request_form(request, slug=None):
agency = get_object_or_404(Agency, slug=slug)
office = agency.office_set.first()
- template = env.get_template('request/form.html')
+ template = env().get_template('request/form.html')
return HttpResponse(template.render(agency=agency, office=office))
def request_start(request):
- template = env.get_template('request/index.html')
+ template = env().get_template('request/index.html')
return HttpResponse(template.render())
@@ -34,7 +37,7 @@ def request_success(request, id):
office = foia_request.office
agency = office.agency
- template = env.get_template('request/success.html')
+ template = env().get_template('request/success.html')
return HttpResponse(template.render(
foia_request=foia_request, requester=requester, office=office,
agency=agency))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment