print the value of a variable in Python/Django?


In PHP I'm used to being able to do print $var or print_r($var).

I can print variables in my views in python but they end up in my cmd window not on the page itself. This is fine for some things but windows' cmd window isn't exactly the most readable when it starts wrapping output and turning it into gibberish.

I tried doing {% print somevar %} in the django template, but I get TemplateSyntaxError: Invalid block tag: 'print'

So, for someone who's new to Python how do I easily see the value of a variable?

10/11/2012 8:53:54 PM

Accepted Answer

{{ this_is_my_variable_that_is_passed_to_my_view }}

the {{ allow variable access to the item which will call the items __unicode__ function if it exists otherwise it will call its __str__ function

10/11/2012 8:49:59 PM

{{ your_variable }} will print the value.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow