我們很多時候獲取URL的某部分內容,而bottle在這方面能提供方便的函數給我們使用。(又是非常強悍的request對象)
下面給出代碼和測試結果
~~~
# coding:UTF-8
from bottle import Bottle, request
app = Bottle()
@app.get('/abc/123')
def index():
return `這個地方替換成測試的變量`
app.run(host="127.0.0.1", port=8000, reloader=True, debug=True)
~~~
測試網址: http://127.0.0.1:8000/abc/123?type=qwe&action=debug#zxc
| 變量名 | 輸出結果 |
| -- | -- |
| request.fullpath | /abc/123 |
| request.query_string | type=qwe&action=debug |
| request.path | /abc/123 |