Speed up development with full-stack environments for every branch.

Learn More

[TurboGears] Validation errors in template with Bootstrap [Python and formencode]

Forked from TurboGears Forms Validation.

45 Runs 82 Views 3 Copies

Shows how to display validation errors in genshy template with Bootstrap



forostm 1

published 3 years ago

from wsgiref.simple_server import make_server
from tg import TGController, AppConfig, expose, validate
from formencode.validators import String, NotEmpty, Int
from formencode import All

class RootController(TGController):
  def index(self, **kw):
    return dict(values= kw or {'name':'', 'age':''})

  @validate(validators={"name":String(min=4), "age":All(Int(),NotEmpty(messages=dict(empty='Enter something')))}, error_handler=index)
  def submit_name(self,name,age):
    return dict(name=name, age=age)
config = AppConfig(minimal=True, root_controller=RootController())
config.renderers = ['genshi']

print "Serving on port 80..."
httpd = make_server('', 80, config.make_wsgi_app())
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).