[英]python + tornado : 404 on imported request handler
im trying to build a tornado app using python. 我正在尝试使用python构建龙卷风应用程序。 I've been able to build a basic routing system as such :
我已经能够建立一个基本的路由系统,例如:
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Default endpoint.")
class CountHandler(tornado.web.RequestHandler):
def get(self):
self.write("Count endpoint.")
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
(r"/count", CountHandler),
])
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
What i want to achieve is to import those handler class ( from a specific handlers
folder ) instead of defining them in this file ( they might get bigger ). 我要实现的是导入这些处理程序类(从特定的
handlers
文件夹),而不是在此文件中定义它们(它们可能会变大)。 To do so i've extracted my CountHandler
class into it's own separate file and i'm importing it as such : 为此,我已将
CountHandler
类提取到它自己的单独文件中,并且将其导入为:
from handlers import CountHandler
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Default endpoint.")
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
(r"/count", CountHandler),
])
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
the CountHandler
class haven't changed a bit, but now i'm getting 404 on my /count
endpoint. CountHandler
类没有改变,但是现在我在/count
端点上得到404。 Am i doing something wrong ? 难道我做错了什么 ?
Fixed it ! 修复 !
In my import, i import the whole CountHandler
lib. 在导入过程中,我将导入整个
CountHandler
库。 Therefore if i want to use the class CountHandler
in my code it should be CountHandler.CountHandler
( ImportedLib.Myclass
) 因此,如果我想在代码中使用
CountHandler
类,则应为CountHandler.CountHandler
( ImportedLib.Myclass
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.