Michael Bates
Michael Bates

Reputation: 1934

All responses are returning with 'None' appended

In my Google App Engine app every request returns with 'None' appended.

For example I have my own view controller implementation and when I return

self.response.out.write(view.toString())

I get the view as expected but there is 'None' appended to the end of the string

I thought it might have been my view controller implementation but if I just return

self.response.out.write("")

Then I just get 'None'

I think this happened since I changed from the webapp framework to the webapp2 framework.

Any ideas?

Upvotes: 3

Views: 172

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124318

When the webapp2 framework calls one of your handler methods, it uses the return value of that method as the response value to the browser.

You are not returning anything from your methods, however. You are writing directly to the response instead (which is fine). When you do that, you need to return an empty string:

return ''

The default return value for python functions without an explicit return statement is None, which is what you are seeing appended.

Alternatively, you could just return the string result instead of writing it to self.response:

return view.toString()

Upvotes: 6

Related Questions