您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在GAE(Google App Engine)中使用Python main()函数?

如何在GAE(Google App Engine)中使用Python main()函数?

似乎解决方案非常简单(它一直躲藏在我的眼前,因为它被隐藏了):__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()
python 2022/1/1 18:47:55 有321人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶