django: debugging code in the view layer

I am developing my first django website.

I have written code in my view layer (the handlers that return an HttpResponse object to the view template (hope I am using the correct terminology).

In any case, I want to put print statements in my views.py file, so that I can debug it. However, it looks like stdout has been redirect to another stream, so I am not seeing anything printed out on my console (or even the browser).

What is the recommended way (best practice) for debugging django view layer scripts?

Answers


Use the Python logging module. Then use the Django debug toolbar, which will catch and display all the things you send to the log.


there are more advanced ways of doing it, but i find dropping

import pdb
pdb.set_trace()

does the job.


Need Your Help

Inputs in material design are not themed

javascript angularjs material-design

I've got working, buttons, carts, lists, but my inputs are not themed like in the demo here: https://material.angularjs.org/#/demo/material.components.input

Best rule for maximum function size?

language-agnostic guidelines code-quality

In another question, a popular answer suggested that large functions demonstrate poor form.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.