Search code examples
pythonbottle

Check if DEBUG in python Bottle


I'm using Bottle 0.12,

how to use the DEBUG global to check if I'm running the development server — or another mean to check in the app if app.run(debug=True) is running?

What I want to achieve is to e.g. make some routes available only in debug

from bottle import DEBUG

@app.route('/debug')
def debug():
    if not DEBUG:
        abort(404)
    return template('debug.html')

I see a global DEBUG variable in bottle source code code which is always False when tested, even if dev server is running with app.run(debug=True)


Solution

  • Try this

    import bottle
    
    @app.route('/debug')
    def debug():
        if not bottle.DEBUG:
            abort(404)
        return template('debug.html')