Is it possible to have multiple GETs in a class in python?
i tried this:
import webapp2
class MainPage(webapp2.RequestHandler ):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write("test")
def get(self, name, surname):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('N: %s S: %s' % (name , surname))
app = webapp2.WSGIApplication([('/.*', MainPage)],
debug=True)
but doesn’t work.
how should i do this? two different files with handling the two different paths?
You can’t have two methods named the same thing in any Python class.
Instead, what you should do is define two different classes, then use different URL pattern matches to choose which is used, rather than sending everything (
/.*) to a single class.Here’s a (very) basic example: