我的路由对我有用,但它是由很长时间构建的,并且由于框架已更新为 webapp2,所以我混合路由并且不知道哪种方式最好。你能帮我改进一下我应该做哪些路由以及如何做路由吗?让框架让路由为处理程序设置默认值还是直接在处理程序上方设置路由更好?
app = webapp2.WSGIApplication([
('/', HomeHandler),
('/shop', FileUploadFormHandler),
('/mypage', MyPageHandler),
webapp2.Route(r'/newpassword/', handler=NewPassword, name='newpassword'),
webapp2.Route(r'/signup/', handler=Signup, name='signup'),
webapp2.Route(r'/myorg/', handler=Myorg, name='signup'),
webapp2.Route(r'/register/', handler=Register, name='register'),
webapp2.Route(r'/education/objectives/index', handler=Objectives, name='objectives'),
webapp2.Route(r'/newdistributor/', handler=NewDistributor, name='newdistributor'),
webapp2.Route(r'/emaillogin/', handler=Emaillogin, name='emaillogin'),
webapp2.Route(r'/paysonreceive/', handler=PaysonReceiveHandler, name='paysonreceivehandler'),
webapp2.Route(r'/paysonhandler/', handler=PaysonHandler, name='paysonhandler'),
webapp2.Route('/passwdreset/<token>', handler=PasswordReset, name='passwordreset'),
('/shop/articles', ShopHandler),
('/info', InfoHandler),
('/update', UpdateHandler),
('/support', SupportHandler),
('/events.*', EventHandler),
('/academy', AcademyHandler),
('/marketing.*', MarketingHandler),
('/dropbox', FileUploadFormHandler),
('/upload', FileUploadHandler),
('/user/register', UserRegisterHandler),
('/tracker', TrackerHandler),
('/generate_upload_url', GenerateUploadUrlHandler),
('/file/([0-9]+)', FileInfoHandler),
('/file/([0-9]+)/download', FileDownloadHandler),
('/file/([0-9]+)/success', AjaxSuccessHandler),
('/home', Home),
('/paypal', Home),
('/sell', Sell),
('/sell/(.*)/', Sell),
('/buy/(.*)/return/(.*)/(.*)/', BuyReturn),
('/buy/(.*)/cancel/(.*)/', BuyCancel),
('/buy/(.*)/', Buy),
('/image/(.*)/', PPImage),
webapp2.Route(r'/login/', handler=NewLoginHandler, name='login'),
webapp2.Route(r'/logout/', handler=NewLogoutHandler, name='logout'
),
webapp2.Route(r'/secure/', handler=SecureRequestHandler,
name='secure'),
webapp2.Route(r'/create/', handler=CreateUserHandler,
name='create-user'),
], config=config)
因此,当添加一个新的 URI 时,我必须同时添加到 app.yaml、路由和处理程序 clas 以及一个不理想的模板,因为这些地方太多了,无法添加东西只是为了从 WSGI 获得响应。所以我想重新编写代码以使其使用更多默认值,例如,如果我添加一个 RequestHandler 类,那么它应该有一个默认路由,因为它已经有一个唯一的名称。框架能做到吗?
感谢您的任何回答或评论