Reputation: 2656
def gettable(request):
reqdata = request.POST
data = reqdata['dataabc']
# print data
return HttpResponse("OK")
This works, but as soon as I uncomment print data
, I see a 500
response in my dev console.
Why could this be happening? I just need to print a couple of things to the console to test.
Upvotes: 0
Views: 102
Reputation: 24344
In python 3, print
is a function.
Using print
as a statement will fail and raise an exception which will terminate your view function prematurely and cause an error 500
.
print
is bad practice in libraries and in server-side / background tasks code. please use the logging
module instead. django even has a section for how to configure and use logging
properly.
https://code.google.com/p/modwsgi/wiki/DebuggingTechniques
Prior to mod_wsgi
version 3.0, you would see this when using print
with sys.stdout
:
IOError: sys.stdout access restricted by mod_wsgi
and you would need to explicitly use a file, e.g.:
print >> sys.stderr, data # python 2
You can however disable the restriction by editing your configuration and using the WSGIRestrictStdout
directive.
Upvotes: 2
Reputation: 41
Completely agree with dnozay. Logging module is a way to go.
More about print statements with wsgi: http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html?m=1
Upvotes: 0