PylonsHQ.

Layout: Fixed-width
  Dashboard > Pylons Cookbook > Home > Forms
  Pylons Cookbook Log In | Sign Up   View a printable version of the current page.  
  Forms
Added by Mike Orr, last edited by Michael Brickenstein on Jun 22, 2009  (view change) show comment
Labels: 
(None)

Pylons has a modular approach to forms. Well, it has a modular approach to everything so this is not surprising. In Pylons you write your form by hand using WebHelpers functions to generate the individual input tags (including a file upload tag). Then you use FormEncode in your controller to validate the fields ("Is 'age' a positive integer?") and formencode.htmlfill to insert error messages into pseudo-HTML tags you've placed in the form.

If you don't like writing forms manually, several third-party libraries providing widgets or form generation have been successfully used in Pylons applications. Most of these do not handle validation: you'll still need FormEncode/htmlfill for that.

ToscaWidgets

ToscaWidgets is a high-level form builder originally created for TurboGears. A ToscaWidget combines an HTML mini-template (an input field or any other HTML chunk) with its corresponding styles and JavaScript into a single portable object which can be deployed at will in your HTML pages, and the CSS and Javascript will automatically be put in the right place. One such widget is a WYSIWYG text box. You can also combine multiple input fields or widgets into compound widgets such as an address widget or date picker.

The Tutorials page on the ToscaWidgets website has some Pylons-specific examples to get you started.

DBSprockets

From the docs: "The goal of DBSprockets is to give the developer the power to simply generate web content from available database definitions. Because DBSprockets relies heavily on Toscawidgets, it is framework-independent. It is easy to implement forms on TG, TG2, Django, Grok, and Pylons using DBSprockets' primitives."

You might say that DBSprockets is the easiest way to get up and running with ToscaWidgets forms if you are using SQLAlchemy for your database definitions. Follow the documentation on Using twForms with Pylons. Part 1 and then use the primitives in DBSprockets to generate the custom forms.

Django's newforms

You can also use django.newforms library in a Pylons app with minimal fuss. See Using django.newforms with Pylons for more info.

FormAlchemy

FormAlchemy generates form fields based on SQLAlchemy mapped classes.

Rum

Rum is a framework to develop CRUD web applications, usually used in the "admin" back-end of a website.

Site running on a free Atlassian Confluence Open Source Project License granted to Pylons. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.3.3 Build:#645 Feb 13, 2007) - Bug/feature request - Contact Administrators

Powered by Pylons - Contact Administrators