Chapter 14.3.11. Working with Query Strings

Something that comes up fairly often in working on web pages is creating query strings for URLs or parsing a query string that you have in hand. MochiKit.Base provides a pair of functions that help out with this.

parseQueryString(str, useArrays=false) takes an encoded string and returns an object with either the values as strings or the values as lists. A couple of examples will make this clear:

  >>> isp_info = parseQueryString("name=Hosty%20Most&city=South%20Barton")
  [object Object]
  >>> isp_info.name
  "Hosty Most"
  >>> isp_info.city
  "South Barton"

In this example, you can see a URL encoded query string get converted into a convenient object. It’s possible to also have multiple values for each parameter ...

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.