Chapter 16.2.1. Custom Form Layout

As we’ve already seen, it is easy to just take a list of form elements and build a WidgetList, pass it to your form and have everything automatically generated for you.

But, what do you do when you want to customize the layout of the resulting form?

Fortunately, TurboGears form widgets have a built mechanism that makes creating custom form templates easy.

If you have defined this form in your controller:

from turbogears import widgets

class MyForm(widgets.Form):
   template = "widgets.templates.wikiform"
   fields = [widgets.CalendarDateTimePicker("date"), widgets.
TinyMCEWidget("text")]

You can create a wikiform.kid template which lets you pick exactly where to render each of the widgets in your form.

<form xmlns:py="http://purl.org/kid/ns#" ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.