Python编程系列---使用字典实现路由静态路由

 1 def index():
 2     print('Index Page....')
 3 
 4 def bbs():
 5     print('BBS Page....')
 6 
 7 def login():
 8     print('Login Page....')
 9 
10 def center():
11     print('Center Page....')
12 
13 def other():
14     print('访问页面不存在....')
15 
16 def logout():
17     print('Logout Page...')
18 
19 # 实现一个路由表,将url和功能函数的对应关系存到这个字典中
20 router_dict = {'index.html':index,'bbs.html':bbs}
21 
22 def run(url):
23     # 通过传入访问地址,获取对应的功能函数
24     func = router_dict[url]
25 
26     func()
27 
28 
29 run('index.html')
30 
31 run('bbs.html')

如果你和我有共同爱好,我们可以加个好友一起交流哈!

Python编程系列---使用字典实现路由静态路由