Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django dump out a variable

Tags:

django

In Django can I dump out a variable to see what is in it within a view (not using command line)?

for example:

device = mobile(request)
    print device
    abort

or 
 device = mobile(request)
 return HttpResponse(device)
like image 323
jason Avatar asked Mar 30 '26 17:03

jason


1 Answers

Writing to a file is usually a fool-proof way to "dump" data as a debug method when you are working with a hooked framework that doesn't otherwise lend itself well to direct debugging.

e.g.

device = mobile(request)
with open('path/to/debug_out.txt', 'w') as outfile:
    outfile.write(device)
abort

for convenience, you could put this in a predefined function in some debug helper module. Alternatively, you could use sys.excepthook to automatically write all exceptions to this file, before forwarding/re-raising them.

like image 195
Preet Kukreti Avatar answered Apr 01 '26 11:04

Preet Kukreti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!