Reputation: 1294
im trying to build a tornado app using 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 ). To do so i've extracted my CountHandler
class into it's own separate file and i'm importing it as such :
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. Am i doing something wrong ?
Upvotes: 1
Views: 251
Reputation: 1294
Fixed it !
In my import, i import the whole CountHandler
lib. Therefore if i want to use the class CountHandler
in my code it should be CountHandler.CountHandler
( ImportedLib.Myclass
)
Upvotes: 1