WSGI by HTTP GET

John Nagle nagle at animats.com
Sun Oct 3 14:01:17 EDT 2010


On 10/2/2010 6:15 PM, Niklasro wrote:
> Hello
> Getting a web same page with 2 or more possible "states" eg business
> part, private part or all parts, can you recommend a way to represent
> the states via HTTP GET? Feasible way could be ?business=business, ?
> type=business, ?business=true or others. Should I minimize casting the
> variable? Which type should I reason, boolen or string? I now use
> seemingly arbitrary ?t=w to represent a state which technically works
> leaving a more readable and maintainable solution to wish.
> Thanks
> Niklas

     First, bear in mind that every data value you get from a web
interface is a raw string of bytes.  You have no assurance that it is
a "Boolean".  You're not even sure it will convert to "str" or
"unicode".  It may legitimately contain "%" type URL escapes.
(Even if you think you control the URL format, a proxy, URL
shorterner, or other intermediary may do some format conversion.)

     If you want to pass a "boolean" variable, I'd suggest sending
"http://www.example.com&val=t".  If you want to send False, omit
"val". On the read side, look for "val", and if the result
starts with "t" or "T", accept it as True.  Otherwise, False.

				John Nagle



More information about the Python-list mailing list