URL完全匹配(具體的url)
/index
URL模糊匹配(你根本就不知道index后面是什么,它根本不會返回參數)
/index/\d
URL帶組匹配(主要有個'()',它的作用主要是返回參數,你處理的類中一定要有個參數接受)
/baidu/(.*)
實例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import web urls = ( '/index' , 'AbsoluteUrl' , '/index/\d' , 'AmbiguousUrl' , '/index/(.*)' , 'GroupUrl' ) #具體的url處理類 class AbsoluteUrl: def GET( self ): web.header( 'Content-type' , 'text/html;charset=utf-8' ) return u 'URL完全匹配' #模糊的url處理類 class AmbiguousUrl: def GET( self ): web.header( 'Content-type' , 'text/html;charset=utf-8' ) return u 'URL模糊匹配' #分組的url處理類 class GroupUrl: def GET( self ,name): #如果你這里是帶組匹配,一定要添加參數,用來接收你返回的參數 web.header( 'Content-type' , 'text/html;charset=utf-8' ) return u 'URL帶組匹配--' + name app = web.application(urls, globals ()) if __name__ = = '__main__' : app.run() |
問題
1. urls為何不能使用dict,難道和它的原理有關
2. globals() 的作用還有哪些
3. 為何http://0.0.0.0:8080/,為何我們運行的時候一定要localhost:8080,這樣設計有什么好處?
以上就是python腳本框架webpy的url映射詳解的詳細內容,更多關于webpy的url映射的資料請關注服務器之家其它相關文章!
原文鏈接:https://blog.csdn.net/guofeng93/article/details/54170844