Andy McKay

Jan 19, 2009

Django form rendering


The other day I was putting on an iPhone skin for Arecibo. Just a HTML and CSS wrapping of the site using IUI. But the form rendering options for forms aren't quite right since IUI is very specific about the HTML is laid out.

There's a simple way to fix that though, add a custom method that outputs it the way I want:

class Form(forms.Form):
    ....
    def as_iui(self):
        return self._html_output(u"""
        <div class="row">
            %(label)s
             %(field)s%(help_text)s
        </div>
        """, u'%s', '', u' %s', True)

Calling form/as_iui gives us the form rendered just as IUI want's it.