pythonflaskwing-ide

How can I run the full Flask Tutorial app in the Wingware IDE?


How can I run the full Flask Tutorial app in the Wingware IDE?

I've been using Flask under Wing Pro 7.2 for some time, and can get control because I start Flask by doing app.run() in Wing.

I conceived a wish to trace through the official working version of the completed tutorial, obtained by git clone https://github.com/pallets/flask

This works fine (using 'flask run'), and I now have the complete source. But there's no app.run() anywhere. I tried putting one in init.py:

    def create_app(test_config=None):
        #...
        db.init_app(app)
        return app

    RUN = True
    if RUN:
        app= create_app()
        app.run()

and flask starts up, but throws an error on request 'localhost:5000/', which normally fires up a database form.

Is there a starting point in the Python code somewhere?

Or, is it possible to attach Wing to a running flask, and tell it about the source files? There is a bit in the Wing manual about attaching, but it seems to demand information about the target that we lack.


Solution

  • I managed to start the tutorial by creating a file main.py in the same directory as the flaskr package, with this contents:

    import flaskr
    app = flaskr.create_app()
    app.debug = False
    app.run(use_reloader=True)
    

    Then I set this as the main debug file in Wing.

    To make debugging work correctly, you may also need to set the Python Executable in Project Properties (from the Project menu) to the Python command line or activated env you want to use.

    Also, it is important to set Debug/Execute > Debug Child Processes in Project Properties to Always Debug Child Processes. Otherwise the process actually running the app code is not debugged.

    This works but results in a SQL error because the table 'post' does not exist if you did not already run the following first to initialize the database:

    $ export FLASK_APP=flaskr
    $ export FLASK_ENV=development
    $ flask init-db
    

    Once I did that, everything worked for me.