Requests¶
For the following we’re assuming that all requests come through the route:
routes = {
'example': {
'path': '/path',
'options': { 'controller': 'Public' }
}
}
Accessing request variables¶
Accessing GET variables¶
Assuming the following http request:
/path/?query=string&value=something
class Public(controllers.Rest):
def GET(self):
query = self.request.get['query'] # string
Accessing POST variables¶
Assuming the following http request:
/path
With the following key/value pairs of data being posted: data: something
class Public(controllers.Rest):
def GET(self):
data = self.request.post['data'] # something
Accessing FILE variables¶
Assuming the following http request:
/path
With
<input type="file" name="a_file" />
being posted.
class Public(controllers.Rest):
def GET(self):
file = self.request.files['a_file'] # cgi.FieldStorage
Accessing cookies¶
Assuming the following http request:
/path
class Public(controllers.Rest):
def GET(self):
cookies = self.request.cookies # CookieDict
Accessing session data¶
Assuming the following http request:
/path
With the following data being stored in the session: data: value
class Public(controllers.Rest):
def GET(self):
session = self.request.session
session_data = session['data'] # value
session.id # id of the session
Accessing SERVER variables (environ variables)¶
class Public(controllers.Rest):
def GET(self):
server = self.request.server['PATH_INFO'] # /path