Your SlideShare is downloading. ×
Django debugging
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Django debugging

1,164
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,164
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Debugging in Django Glen Zangirolami http://twitter.com/glenbot http://theglenbot.com
  • 2. Debugging Tools
    • pdb – Python Debugger
      • http://docs.python.org/library/pdb.html
    • django-debug-toolbar
      • https://github.com/robhudson/django-debug-toolbar
    • Fire Logger
      • http://firelogger.binaryage.com/
    • Profile Middleware
      • http://djangosnippets.org/snippets/186/
  • 3. Debugging with pdb import pdb pdb.set_trace()
  • 4. Debugging with pdb - commands l (list): Shows the current code around the line that your on. The line that is about to be executed has a -> before it. n (next): Executes the current line and moves to the next in the current file. c (continue): Finishes the debugging session. If there are more breakpoints (or if your set_trace() code gets called again before the request finishes) then you will get back to the debugger, otherwise the requests will complete back to the browser. s (step): Goes down into the next level of execution (presumably a different file). You can follow your code through Django's internals this way. This is really good for finding bugs and getting a better understanding about how Django works. w (where): Shows you a backtrace of the calls that have gotten you to the current point in the code execution. This is really handy for the following 2 commands. u (up): Allows you to go up one level in the backtrace. d (down): Allows you to go down one level in the backtrace. These two commands allow you to see where you came from, and what variables were called where. This lets you see how the state ended up the current way that it did, which is great for figuring out how to fix it. :) locals(): This isn't a debugger function, but it is really handy for seeing what is in the current scope that you can muck around with. locals().keys() is really nice too just to see the variables that are there, because request tends to pollute the locals() command.
  • 5. Debugging with django-debug-toolbar pip install django-debug-toolbar MIDDLEWARE_CLASSES = ( ... 'debug_toolbar.middleware.DebugToolbarMiddleware', … ) INSTALLED_APPS = ( ... 'debug_toolbar', ... )
  • 6. Debugging with Fire Logger pip install firepython MIDDLEWARE_CLASSES = ( ... 'firepython.middleware.FirePythonDjango', … )
  • 7. Debugging with profile middleware Copy/paste code from snippet MIDDLEWARE_CLASSES = ( ... 'profile_middleware.ProfileMiddleware', … )
  • 8. References and Questions
    • http://ericholscher.com/blog/2008/aug/31/using-pdb-python-debugger-django-debugging-series-/
    • 9. Questions?