Equivalent of PHP "echo something; exit();" with Python/Django?


Question

Sometimes the best way to debug something is to print some stuff to the page, and exit(), how can I do this in a Python/Django site?

e.g. in PHP:

echo $var;
exit();

Thanks

1
19
4/30/2010 8:43:05 PM

Accepted Answer

Put this in your view function:

from django.http import HttpResponse
return HttpResponse(str(var))
16
4/30/2010 8:45:37 PM

I just wanted to give an alternative answer: Simply use print statements and serve your django site with python manage.py runserver

In this case the print statements show up in your shell, and your site continues functioning as it would normally.


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