Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Templater(object):
- def __init__(self, **kwargs):
- self._args = kwargs
- def __setattr__(self, name, value):
- if name == "_args":
- return super(Templater, self).__setattr__(name, value)
- self._args[name] = value
- def __getattr__(self, name):
- try:
- return self._args[name]
- except KeyError, ex:
- raise AttributeError("%s instance has no attribute %r" % (self.__class__.__name__, name))
- def render_to_response(self, filename, context_instance=None, mimetype=None):
- return render_to_response(filename, self._args, context_instance, mimetype)
- def view(request, arg):
- t = Templater(arg=arg)
- t.object = get_object_or_404(User, username=request.user.username)
- t.arg2 = "foobar"
- # Send {'arg': arg, 'object': <User..>, 'arg2': 'foobar'} to template.html
- return l.render_to_response("template.html", context_instance=RequestContext(request))
Add Comment
Please, Sign In to add comment