Chapter 20.2.3. Unicode in CherryPy’s Request/Response Cycle

In the default configuration, TurboGears converts all incoming parameters that are passed to your controller into Unicode strings. Here is a small test case:

  @expose()
  def process(self, name=None):
      return "Name is %r" % name
      # -> yields something like "Name is u'Smarty'"

Usually you would just keep it that way. If for some reason you disable this with the decoding_filter option, you might want to use turbogears.validators.UnicodeString to decode the selected parameters by hand:

 @expose() @turbogears.validate(validators={'name':validators.UnicodeString()}) def process(self, name=None, name2=None): return "Name is %r while name2 is %r" % name # -> yields something like "Name is u'Smarty' ...

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.