CGI

GET

import cgi

form = cgi.FieldStorage()
if (form.has_key("param_name")):
param_value = form["param_name"].value
  • If the parameter was not sent, there is no key for the parameter (in the form object).

POST

import cgi

form = cgi.FieldStorage()
if (form.has_key("param_name")):
param_value = form["param_name"].value
  • If the parameter was not sent, there is no key for the parameter (in the form object).

Environment variables

import os

env = os.environ

host = env["HTTP_HOST"]
url = env["REQUEST_URI"]

base_url = env["SCRIPT_NAME"]
url_query = env["QUERY_STRING"]

HTML forms

Text field

  • If the field is empty, there is no key for the field (in the form object).

Radio button

  • If no item was selected, there is no key for the field (in the form object).

Check box

  • If the field is unchecked, there is no key for the field (in the form object).

Single-selection list

  • If no item was selected, there is no key for the field (in the form object).

Multiple-selection list

  • The value is retrieved as a list of strings.
  • If no items were selected, there is no key for the field (in the form object).