using the pycharm debugger with a flask application factory using the pycharm debugger with a flask application factory flask flask

using the pycharm debugger with a flask application factory


Try configuring this python running configuration in "Edit Configurations". After that, run in debug mode.

PyCharm configuration example


If you are using the application factory pattern (i.e. using creat_app() WITHOUT a run.app() main) you can use your standard 'flask' run configuration template (community version may not have these, not sure). However, you'll notice that the debugger wont stop at breakpoints because the flask app in DEBUG runs the reloader which means it runs in different threads and Pycharm cant catch it. So to make it break not just at lunch but any API call you want to debug make sure you:

  • select DEBUG checkbox
  • add --no-reload as a flask argument
  • add --without-threads as a flask argument

This was the only way I could get full debug support:

Run Configuration


You ran the project manually by CLI. For using PyCharm IDE debug you must configure PyCharm for your project and then run this by PyCharm.
But if you want to run the program without PyCharm, you can use the pdb library for debugging destinations. Try the code below:

import pdbdef my_def():    try:        x = 7 / 0    except Execption as e:        pdb.set_trace()

When running this program you can see the interactive line on your CLI...