Section thirty-third to complete the routing function with parameters by decorators

URL_DICT = dict()

def route(url):
    def set_func(func):
        URL_DICT[url] = func
        def call_func():
            func()
        return call_func
    return set_func

@route('center_p')
def center_p():
    pass

@route('index_p')
def index_p():
    pass

DEF file application (the env, The start_response):
     '' ' the env is an empty dictionary, The start_response is quoted web server in a method, a function return the body ' '' 
    The start_response ( ' 200 is the OK ' , [( ' the Content-the Type ' , ' text / HTML; charset = UTF-. 8 ' )])
    file_name = env['PATH INFO']

    the try :
         return URL_DICT [file_name] ()
     the except Exception AS RET:
         return  ' an abnormality S% ' % STR (RET)

 

Guess you like

Origin www.cnblogs.com/kogmaw/p/12602579.html