Debugging flask with pdb

prosseek picture prosseek · Nov 8, 2014 · Viewed 10.2k times · Source

I'm trying to use pdb to debug flask application. Setting break point is easy; I just use b index to break when index() is invoked or b 44 to set a break point at line 44.

Breakpoint works with b 44 which is the start of the main, but b index doesn't work. In the command line, "Index is called" is printed to indicate that the method is invoked, but it does not stop in the pdb.

@app.route('/', methods=['GET', 'POST'])
def index():
    print "Index is called"
    name = None
    ...
    return render_template('index.html', form=form, name=name)

if __name__ == '__main__':
    manager.run() # line 44

What might be wrong?

Answer

David Sanders picture David Sanders · Nov 8, 2014

You can do this at the line where you want execution to break:

import pdb; pdb.set_trace()

Just make sure you delete it before you commit :).