yibin001
V2EX  ›  问与答

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

  •  
  •   yibin001 · May 27, 2014 · 6643 views
    This topic created in 4394 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
        1
    CMGS  
       May 27, 2014
    抽出一个公共函数
    yibin001
        2
    yibin001  
    OP
       May 27, 2014
    @CMGS
    呃~貌似只能如此了。
    cloverstd
        3
    cloverstd  
       May 27, 2014 via iPhone
    用 httpclient 请求你要调用的 get
    zhwei
        4
    zhwei  
       May 27, 2014 via Android
    直接重定向不行吗?
    chenkun0128
        5
    chenkun0128  
       May 27, 2014
    wodemyworld
        6
    wodemyworld  
       May 27, 2014
    外包项目随便写,如果将来还得自己维护就少欠技术债,不然将来还得吃自己的屎
    yibin001
        7
    yibin001  
    OP
       May 27, 2014
    @chenkun0128
    谢谢。
    stackpop
        8
    stackpop  
       May 27, 2014
    requests.get('/handlerURL')
    taine
        9
    taine  
       May 27, 2014
    lz,问句题外话,程序中的handler中文名称是什么?处理器,还是处理程序?
    yibin001
        10
    yibin001  
    OP
       May 27, 2014   ❤️ 1
    @taine
    处理程序
    taine
        11
    taine  
       May 27, 2014
    @yibin001 谢谢!
    latyas
        12
    latyas  
       Jul 14, 2015   ❤️ 1
    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   ·   Solana   ·   2919 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 05:35 · PVG 13:35 · LAX 22:35 · JFK 01:35
    ♥ Do have faith in what you're doing.