Bottle.py error routing

前端 未结 3 947
再見小時候
再見小時候 2021-02-13 03:46

Bottle.py ships with an import to handle throwing HTTPErrors and route to a function.

Firstly, the documentation claims I can (and so do several examples):



        
3条回答
  •  别跟我提以往
    2021-02-13 04:34

    If you want to embed your errors in another module, you could do something like this:

    error.py

    def custom500(error):
        return 'my custom message'
    
    handler = {
        500: custom500,
    }
    

    app.py

    from bottle import *
    import error
    
    app = Bottle()
    app.error_handler = error.handler
    
    @app.route('/')
    def divzero():
        return 1/0
    
    run(app)
    

提交回复
热议问题