Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug with django?

Tags:

django

I'm starting to learn django and I was 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.

like image 681
aporat Avatar asked Dec 09 '22 05:12

aporat


2 Answers

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.

like image 190
Eric Fortin Avatar answered Feb 14 '23 06:02

Eric Fortin


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.

like image 33
Martin Thurau Avatar answered Feb 14 '23 07:02

Martin Thurau