How to debug Web2py applications?
Asked Answered
A

9

19

Is it possible? By debug I mean setting breakpoints, inspect values and advance step by step.

Apollinaire answered 24/11, 2008 at 19:27 Comment(1)
The title says win2py, and the tag says web2py. Can you correct one of them?Allheal
P
10

You can do remote debugging of python web apps over TCP/IP with winpdb.

(Link appears down as of June 2019. Try PyPI winpdb)

Penuchle answered 25/11, 2008 at 19:3 Comment(1)
Link broken ____Selaginella
A
8

I haven't used web2py, but if it runs in a terminal window, you can use standard pdb stuff. Add this line somewhere in your code:

import pdb; pdb.set_trace() 

This will invoke the debugger and break. Then you can use PDB commands: n to step to the next line, l to list code, s to step into a function, p to print values, etc.

Allheal answered 24/11, 2008 at 20:22 Comment(0)
D
8

One can debug applications built on Web2py using the following set-up:

  1. Eclipse IDE
  2. Install Pydev into Eclipse
  3. Set Breakpoints on your code as needed
  4. Within Eclipse right-click the file web2py.py and select Debug As -> Python Run
  5. When a breakpoint is hit Eclipse will jump to the breakpoint where you can inspect variables and step thru the code
Demantoid answered 30/4, 2009 at 10:4 Comment(0)
B
6

You can also use Visual Studio 2010. Here's how:

  • Download and install Python Tools for Visual Studio.
  • Create a new project from existing code (File > New > Project From Existing Code...)
  • Specify your web2py folder and use the defaults.
  • Right-click on web2py.py and choose Set as Startup File.
  • Set breakpoints and hit F5 (run) or right-click on web2py.py and choose Start with Debugging.

This is a nice setup if you already use visual studio.

Booze answered 8/3, 2012 at 15:45 Comment(0)
A
1

Yes, it is possible, Due to the "span prevention" I am still not allowed to post screenshots, but here is a full screenshot hosted at my website:

http://static.techfuel.net/debug_web2py.png

Ascender answered 10/11, 2009 at 4:29 Comment(0)
H
1

I'm debugging web2py applications with Eclipse and PyDev. Here is an article: http://www.web2pyslices.com/main/slices/take_slice/2

Harbird answered 26/1, 2011 at 15:27 Comment(0)
P
0

As Carl stated, it is as easy as:

  1. Installing PyDev in Eclipse
  2. Right Click on your Web2Py project, selecting Debug As > Python Run
  3. Selecting web2py.py as the file to run

No other plugins or downloads are needed.

Portaltoportal answered 6/5, 2010 at 14:42 Comment(0)
L
0

Here is an article on debugging python with pdb, which will work with web2py. http://sontek.net/debugging-python-with-pdb

Lisette answered 29/10, 2010 at 5:29 Comment(0)
C
0

@Ned Batchelder is almost right, but the standard way of doing it in web2py is slightly different.

Instead of `import pdb; pdb.set_trace(), you use the code:

from gluon.debug import dbg
dbg.set_trace()

When executing the web application, the application will freeze when it reaches this section of code. You then go to http://127.0.0.1:8000/admin/debug/interact (using the root URL for your application) and it will show a fully interactive, web based debugger:

enter image description here

See documentation.

Constantina answered 1/12, 2018 at 2:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.