celloyee
V2EX  ›  问与答

tornado 中一个 handler 如何调用另一个 handler 的 get 方法?

  •  
  •   celloyee · May 27, 2014 · 6933 views
    This topic created in 4562 days ago, the information mentioned may be changed or developed.
    class home(basehandler):
    def get(self):
    pass

    class profile(basehandler):
    def get(self):
    #如何调用home中的get方法?

    Stackoverflow上找了一个问题,回答也是不能直接调用了。
    http://stackoverflow.com/questions/22928230/calling-post-method-of-one-class-from-another-classs-post-method
    有没有好办法?

    ps.如何引用gist?
    12 replies  •  2015-07-14 11:03:30 +08:00
    CMGS
    CMGS
    May 27, 2014
    1
    抽出一个公共函数
    celloyee
    celloyee
    OP
    May 27, 2014
    2
    @CMGS
    呃~貌似只能如此了。
    cloverstd
    cloverstd
    May 27, 2014 via iPhone
    3
    用 httpclient 请求你要调用的 get
    zhwei
    zhwei
    May 27, 2014 via Android
    4
    直接重定向不行吗?
    wodemyworld
    wodemyworld
    May 27, 2014
    6
    外包项目随便写,如果将来还得自己维护就少欠技术债,不然将来还得吃自己的屎
    celloyee
    celloyee
    OP
    May 27, 2014
    7
    @chenkun0128
    谢谢。
    stackpop
    stackpop
    May 27, 2014
    8
    requests.get('/handlerURL')
    taine
    taine
    May 27, 2014
    9
    lz,问句题外话,程序中的handler中文名称是什么?处理器,还是处理程序?
    celloyee
    celloyee
    OP
    May 27, 2014❤️1
    10
    @taine
    处理程序
    taine
    taine
    May 27, 2014
    11
    @yibin001 谢谢!
    latyas
    latyas
    Jul 14, 2015❤️1
    12
    from tornado.web import Application, RequestHandler
    from tornado.ioloop import IOLoop
    from functools import partial


    class FuckinHandler(RequestHandler):
    def get(self):
    func = partial(Handler.get.im_func, self)
    func()

    class Handler(RequestHandler):
    def get(self):
    self.write('test')
    self.finish()

    WEBSERVER_PORT = 10000
    application = Application([
    (r'/', FuckinHandler),
    ])

    application.listen(WEBSERVER_PORT)
    IOLoop.instance().start()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2156 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 277ms · UTC 03:21 · PVG 11:21 · LAX 19:21 · JFK 22:21
    ♥ Do have faith in what you're doing.