Debugging `render` with `pdb`: How to provide the `request` argument? How to view the output reponse?

@CodenameTim once pointed out that you can use pdb to debug Django. That sounds great, but I’ve never had reason to use it until today.

Today the thing I’m trying to debug is a call to render(). Its output is of type HTTPResponse, and its first input is an HTTP request (neither pydoc nor the online docs specify the exact type name). I can start a python3 shell and import the library defining my buggy call to render(), but I don’t know how to provide the request argument, and even if I did, I wouldn’t know how to view the output response.

(In my present case, viewing the response is unnecessary – I hit a bug before I get there – but I imagine it’s useful in general.)


I would write a test using that view. You can use the Client or RequestFactory (generates a request like you want). This entire section of the documentation is helpful. I actually had to refer back to it quite often this week for some tests.

You don’t need to actually write the tests. You can use the shell as you’ve been doing. But, it may make running this and other similar validations later on easier.