Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test TurboGears request.validation in minimal mode
from wsgiref.simple_server import make_server
import tg
from tg import RestController, expose, validate, MinimalApplicationConfigurator
from formencode import validators
class RootController(RestController):
@validate({"man":validators.String(not_empty=True), "pin":validators.String(not_empty=True), "sou":validators.String(not_empty=True), "win":validators.String(not_empty=True)})
def calc(self, **kw):
validation_status = tg.request.validation
errors = [{key: str(value)} for key, value in validation_status.errors.items()]
return dict(errors=errors)
# Configure a new minimal application with our root controller.
config = MinimalApplicationConfigurator()
'root_controller': RootController()
# Serve the newly configured web application.
print("Serving on port 8080...")
httpd = make_server('', 8080, config.make_wsgi_app())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment