6.3. Environment data
Access to the HTTP environment is provided through global variables available in the script's namespace :
- Read-only variables
REQUEST_HANDLER
is an object representing the request ; a useful attribute isclient_address
, a 2-element tuple with client IP address and port, for example ('127.0.0.1', 1825)ENVIRON
is a dictionary with the CGI environment variables :SERVER-SOFTWARE, REQUEST-METHOD, QUERY-STRING,
, etc.HEADERS
is a dictionary with the HTTP headers sent by the browser : the key is the header name, the value is the header's value. For instanceHEADERS["accept-language"]
will return the value of the accept-language headerACCEPTED_LANGUAGES
is a list of languages accepted by the user's browser, ordered by preference. The items are two-character strings identifying the language, according to the ISO 639 codification (en
for English,fr
for French, etc)COOKIE
is a dictionary-like SimpleCookie object (in PythonCookie
module) that stores the cookies sent by the web browser with the HTTP request (see the section on cookies)Role()
is a function that returns the user's role, as defined in the built-in user management framework (see the chapter on authentication)THIS
is an instance of the classTarget
(in k_target.py) representing the current script
- Read-write variables
SET_COOKIE
is another SimpleCookie object to which you can set keys and values which will be stored by the web browser as cookies (see the section on cookies)RESPONSE
is a dictionary in which you'll set values for the response header that will be sent to the client. This dictionary is insensitive to the case of the keys :RESPONSE['Content-type']
andRESPONSE['CONTENT-type']
return the same result
The list of built-in names is described in the namespace section