[root@ju bottle]# cat error.py #!/usr/bin/env python #coding=utf-8 from bottle importroute,run,error,abort,redirect #訪問頁面出錯,Bottle會顯示一個默認的錯誤頁面,提供足夠的debug信息。你也可以使用error()函數來自定義你的錯誤頁面 @error(404) def error404(error): return '訪問出錯啦!' #一般返回一個錯誤頁面模版,這裏爲了簡單起見,就不寫了 @route('/hello') def hello(): return 'hello!' @route('/redtest') def redtest(): redirect('/hello') #訪問/redtest的時候,會被重定向到/hello頁面 @route('/abort404') def abort404(): abort(404) #當訪問/aborttest時,會觸發404錯誤 @route('/abort500') def abort500(): abort(500) #當訪問/aborttest時,會觸發500錯誤 run(host='0.0.0.0',port=8000)
bottle框架學習(六)之錯誤與重定向
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.