Search code examples
pythondebuggingstep-into

How do I step through/debug a python web application?


I can't seem to find any information on debugging a python web application, specifically stepping through the execution of a web request.

is this just not possible? if no, why not?


Solution

  • If you put

    import pdb
    pdb.set_trace()
    

    in your code, the web app will drop to a pdb debugger session upon executing set_trace.

    Also useful, is

    import code
    code.interact(local=locals())
    

    which drops you to the python interpreter. Pressing Ctrl-d resumes execution.

    Still more useful, is

    import IPython.Shell 
    ipshell = IPython.Shell.IPShellEmbed()
    ipshell(local_ns=locals())
    

    which drops you into an IPython session (assuming you've installed IPython). Here too, pressing Ctrl-d resumes execution.