Created
May 23, 2010 09:50
-
-
Save qoelet/410802 to your computer and use it in GitHub Desktop.
django.views.generic.simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): | |
""" | |
Render a given template with any extra URL parameters in the context as | |
``{{ params }}``. | |
""" | |
if extra_context is None: extra_context = {} | |
dictionary = {'params': kwargs} | |
for key, value in extra_context.items(): | |
if callable(value): | |
dictionary[key] = value() | |
else: | |
dictionary[key] = value | |
c = RequestContext(request, dictionary) | |
t = loader.get_template(template) | |
return HttpResponse(t.render(c), mimetype=mimetype) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment