Skip to content

Instantly share code, notes, and snippets.

@andymccurdy
Created August 26, 2013 18:42
Show Gist options
  • Save andymccurdy/6344969 to your computer and use it in GitHub Desktop.
Save andymccurdy/6344969 to your computer and use it in GitHub Desktop.
class TemplateWidget(object):
"Uses a template to render the widget"
def __init__(self, template, get_value_callable=None):
self.template = template
self.get_value_callable = get_value_callable
def __call__(self, field, **kwargs):
kwargs.update({'field': field})
if self.get_value_callable:
kwargs['value'] = self.get_value_callable(field)
return render_to_string(self.template, kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment