Sævar Öfjörð
unread,Jul 6, 2010, 8:41:38 AM7/6/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi, I've been using the default template loaders and it works fine.
Now I want to add the cached template loader, but I get an error.
I'm using a wrapper function to return responses that include the
request in the context, like this:
# file helpers/helpers.py
from django.template import RequestContext, loader
from django.http import HttpResponse
def return_response(request, dictionary, template, headers={}):
t = loader.get_template(template)
c = RequestContext(request, dictionary)
res = HttpResponse(t.render(c))
for h, v in headers.iteritems():
res[h] = v
return res
The stacktrace:
Traceback:
File "/home/django/project/virtualenv/lib/python2.6/site-packages/
django/core/handlers/base.py" in get_response
106. response = middleware_method(request,
e)
File "/home/django/project/virtualenv/lib/python2.6/site-packages/
django/core/handlers/base.py" in get_response
100. response = callback(request,
*callback_args, **callback_kwargs)
File "/home/django/project/project/views.py" in index
24. return helpers.return_response(request, d, 'frontpage.html')
File "/home/django/project/project/helpers/helpers.py" in
return_response
129. t = loader.get_template(template)
File "/home/django/project/virtualenv/lib/python2.6/site-packages/
django/template/loader.py" in get_template
157. template, origin = find_template(template_name)
File "/home/django/project/virtualenv/lib/python2.6/site-packages/
django/template/loader.py" in find_template
128. loader = find_template_loader(loader_name)
File "/home/django/project/virtualenv/lib/python2.6/site-packages/
django/template/loader.py" in find_template_loader
104. func = TemplateLoader(*args)
Exception Type: TypeError at /
Exception Value: __init__() takes exactly 2 arguments (1 given)
Is there some different way I should approach the template loading?