Skip to content

Instantly share code, notes, and snippets.

@dziegler
Created December 15, 2011 23:43
Show Gist options
  • Save dziegler/1483525 to your computer and use it in GitHub Desktop.
Save dziegler/1483525 to your computer and use it in GitHub Desktop.
A quick and dirty way to use django-uni-form with jinja2.
from django.template import Context, Template
from coffin.template import Library
from jinja2 import contextfunction
register = Library()
@register.object
@contextfunction
def uni_form(context, form, helper=None):
"""
A quick and dirty way to use django-uni-form with jinja2.
The same technique applies to working with other third party django templatetags.
In your jinja2 template::
{{ uni_form(form, form.helper) }}
"""
t = Template("{% load uni_form_tags %}{% uni_form form helper %}")
django_context = Context(context)
django_context.update({'form': form, 'helper': helper})
return t.render(django_context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment