Using Wing with web2py

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


Wing Pro Screenshot

Wing Pro is a Python IDE that can be used to develop, test, and debug Python code and templates written for web2py, a powerful open source web development framework.

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

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

Introduction

Wing allows you to debug Python code and templates running under web2py as you interact with it from your web browser. Breakpoints set in your code from the IDE will be reached, allowing inspection of your running code's local and global variables with Wing's various debugging tools. In addition, in Wing Pro, the Debug Console allows you to interactively execute methods on objects and get values of variables that are available in the context of the running web app.

There is more than one way to do this, but in this document we focus on an "in process" method where the web2py server is run from within Wing, as opposed to attaching to a remote process.

Setting up a Project

The best way to install web2py is to clone the git repository. Be sure to follow the instructions in the readme so you clone all the dependencies recursively.

To create a new project, use New Project in Wing's Project menu with Project Type set to web2py. You'll be able to select or create a source directory for your project and select or create a Python environment. See Creating a Project for details on creating projects in Wing.

After the pressing Create Project, open the Project tool from the Project menu. From there, find and right click on the file web2py.py and select Set As Main Entry Point.

Remote Development

Wing Pro can work with web2py code that is running on a remote host, VM, or container. To do this, you need to be able to connect to the remote system with SSH. Then you can create your project in the same way as above, using the Connect to Remote Host via SSH project type. See Remote Hosts for more information on remote development with Wing Pro.

Debugging

You can now debug web2py by clicking on the green Debug icon in Wing's toolbar and waiting for the web2py console to appear. Enter a password and start the server as usual.

Once web2py is running, open a file in Wing that you know will be reached when you load a page of your web2py application in your web browser. Place a breakpoint in the code and load the page in your web browser. Wing should stop at the breakpoint. Use the Stack Data tool or Debug Console (in Wing Pro) to look around.

An example is to set a breakpoint in applications/examples/views/default/index.html, which is loaded when you go to the URL http://127.0.0.1:8000/examples/default/index (assuming local web2py install running on port 8000).

Notice that breakpoints work both in Python code and HTML template files.

Wing's Debug Console (in the Tools menu) is similar to running a shell from web2py (with python web2py.py -S myApp -M) but additionally includes your entire context and provides auto-completion. You can easily inspect or modify variables, manually make function calls, and continue debugging from your current context.

Usage Tips

Setting Run Arguments

When you start debugging, Wing will show the File Properties for web2py.py. This includes a Run Arguments field under the Debug tab where you can add any web2py option. For example, adding -a '<recycle>' will give you somewhat faster web2py startup since it avoids showing the Tk dialogs and automatically opening a browser window. This is handy once you already have a target page in your browser. Run python web2py.py --help for a list of all the available options.

To avoid seeing the File Properties dialog each time you debug, un-check the "Show this dialog before each run" check box. You can access it subsequently with Debug Environment in the Debug menu.

Hung Cron Processes

Web2py may spawn cron sub-processes that fail to terminate on some OSes when web2py is debugged from Wing. This can lead to unresponsiveness of the debug process until those sub-processes are killed. To avoid this, add the parameter -N to prevent the cron processes from being spawned.

Better Auto-completion

Because of the way web2py is designed, Wing's static analysis engine can fail to find the types of commonly used values like db. To work around this, run to a breakpoint in your code before editing it. This causes Wing to use runtime analysis as well as static analysis to drive auto-completion and other IDE features.

Related Documents

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