Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from inspect import getouterframes, currentframe
- from copy import copy
- from django.shortcuts import render_to_response
- #def render_to_response(*args, **kw):
- # print args, kw
- class Templater(object):
- def __init__(self, **kwargs):
- self.args = kwargs
- self._prev = set()
- def __enter__(self):
- self._prev = set(getouterframes(currentframe())[1][0].f_locals.keys())
- return self
- def __exit__(self, type_, value, traceback):
- current = getouterframes(currentframe())[1][0].f_locals
- newvars = set(current.keys()) - self._prev
- for name in newvars:
- if current[name] is not self:
- self.args[name] = current[name]
- def render_to_response(self, template, context_instance=None, mimetype=None):
- return render_to_response(template, self.args, context_instance, mimetype)
- def view(request, arg):
- a = 1
- with Templater(arg=arg) as t:
- b = 2
- # send {'arg': arg, 'b': 2} to template.html
- return t.render_to_response("template.html", context_instance="ctx", mimetype="mime")
Add Comment
Please, Sign In to add comment