Using Wing with Flask

Index of All Documentation » How-Tos » How-Tos for Web Development »


Wing is a Python IDE that can be used to develop, test, and debug Python code written for the Flask web development framework. Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional programmers, and Wing Personal is a free alternative with reduced feature set.

If you do not already have Wing installed, download it now.

This document describes how to configure Wing for Flask. To get started using Wing as your Python IDE, please refer to the tutorial in Wing's Help menu or read the Quickstart Guide.

Debugging in Wing

To debug Flask in Wing you need to turn off Flask's built-in debugger, so that Wing's debugger can take over reporting exceptions.

To do this, you can set up your main entry point as in the following example:

from flask import Flask
app = Flask(__name__)

...

if __name__ == "__main__":
    import os
    if 'WINGDB_ACTIVE' in os.environ:
        app.debug = False
    app.run()

Notice that this turns off Flask's debugging support only if Wing's debugger is present.

Once this is done, use Set Main Debug File in the Debug menu to set this file as your main debug file in Wing. Then you can start debugging from the IDE, see Flask's output in the Debug I/O tool, and load pages from a browser to reach breakpoints or exceptions in your code.

Use Restart Debugging in the Debug menu or the restart icon in the toolbar to quickly restart Flask after making changes to your code. Or if you have Wing Pro you can automate this as described in the next section.

Passing the --no-debug flag or setting environment variable FLASK_DEBUG=0 are other documented ways to turn of Flask's debug support, although we've had some reports of --no-debug failing to function as expected.

Setting up Auto-Reload with Wing Pro

With the above configuration, you will need to restart Flask whenever you make a change to your code. If you have Wing Pro, you can avoid this by replacing the app.run() line in the above example with the following:

app.run(use_reloader=True)

Then enable Debug Child Processes under the Debug/Execute tab in Project Properties from the Project menu. This tells Wing Pro to debug also child processes created by Flask, including the reloader process.

Now Flask will automatically restart on its own whenever you save an already-loaded source file to disk.

You can add additional files for Flask to watch as follows:

watch_files = ['/path/to/file1', '/path/to/file2']
app.run(use_reloader=True, extra_files=watch_files)

Whenever any of these additional files changes, Flask will also automatically restart.

Related Documents

Wing provides many other options and tools. For more information: