All responses are returning with 'None' appended

google-app-engine, python, python-2.7, webapp2

Solution

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()

Problem

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?

Original source