似乎解决方案非常简单(它一直躲藏在我的眼前,因为它被隐藏了):__name__
是 而不是 !
简而言之,以下代码main()
按预期使用了:
# with main()
import webapp2
class GetHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('in GET')
class SetHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('in SET')
def main():
global app
app = webapp2.WSGIApplication([
('/get', GetHandler),
('/set', SetHandler),
], debug=True)
# Note that it's 'main' and not '__main__'
if __name__ == 'main':
main()