how to debug with django?
I'm starting to learn django and I wa开发者_运维百科s wondering what's the best way to debug a django application?
More specifically, I'm looking for a way to print out variables, in an equivalent way to var_dump statements in php.
While running the development server, you can issue print statement that will get printed in the console output. You can also use pdb while handling a request and debug directly.
You could put these statements in your view code:
import pdb; pdb.set_trace()
to enter interactive debug and trace as long as you want or almost.
I can recommend django-extensions runserver_plus
. It includes the super useful werkzeug debugger. Whenever an exception in dev-mode occurs you can view the code that caused the inspection and open a debug console in you browser that gives you full access to a python REPL with all variables at exception time.
Put django in debug mode and you'll get stack traces when things fail.
I am working on a Django application now using Eclipse with the PyDev plugin. It works really great as a traditional IDE, allowing me to set breakpoints, query the state, and such.
And Martin is right, runserver_plus is awesome.
精彩评论