pythondebuggingflaskideweb-development-server

using the pycharm debugger with a flask application factory


I am typing more print statements than code. It's killing me.

If a flask development server is invoked via below, I can use PyCharm debugger

from ersapp import app

if __name__ == '__main__':
    app.run(debug=True)

I am following the example in Miguel Grinberg's book and an application manager (flask-script) is used. I invoke the server in my application directory like below

(env)$ python manage.py runserver

and in appdirectory/__init__.py

def create_app(config_name):
    webapp = Flask(__name__)
    ...
    return webapp

The debugger in Pycharm would make things easier since that's where I work.


Solution

  • 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 pdb
    
    
    def 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...