Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (31 sloc) 1.22 KB
layout title
Application processors, hooks

Application processors, hooks

Other languages : français | ...


How to use application processors, loadhooks and unload hooks?

Solution application allows adding processors which can do some processing before and after executing the requests

def my_processor(handler): 
    print 'before handling'
    result = handler() 
    print 'after handling'
    return result


Load hooks and unload hooks can be used to do actions at begining and end of requests.

def my_loadhook():
    print "my load hook"

def my_unloadhook():
    print "my unload hook"


you can write or use global variables in hook function, for example: web.header()

def my_loadhook():
    web.header('Content-type', "text/html; charset=utf-8")


Tip: and also can use web.ctx or web.input() in hook.

def my_loadhook():
    input = web.input()
    print input