V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yibin001
V2EX  ›  问与答

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

  •  
  •   yibin001 · 2014-05-27 08:12:35 +08:00 · 6091 次点击
    这是一个创建于 3629 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2015-07-14 11:03:30 +08:00
    CMGS
        1
    CMGS  
       2014-05-27 08:13:25 +08:00
    抽出一个公共函数
    yibin001
        2
    yibin001  
    OP
       2014-05-27 08:14:11 +08:00
    @CMGS
    呃~貌似只能如此了。
    cloverstd
        3
    cloverstd  
       2014-05-27 08:14:43 +08:00 via iPhone
    用 httpclient 请求你要调用的 get
    zhwei
        4
    zhwei  
       2014-05-27 08:25:33 +08:00 via Android
    直接重定向不行吗?
    chenkun0128
        5
    chenkun0128  
       2014-05-27 08:54:32 +08:00
    wodemyworld
        6
    wodemyworld  
       2014-05-27 08:58:40 +08:00
    外包项目随便写,如果将来还得自己维护就少欠技术债,不然将来还得吃自己的屎
    yibin001
        7
    yibin001  
    OP
       2014-05-27 09:02:45 +08:00
    @chenkun0128
    谢谢。
    stackpop
        8
    stackpop  
       2014-05-27 09:33:01 +08:00
    requests.get('/handlerURL')
    taine
        9
    taine  
       2014-05-27 10:04:00 +08:00
    lz,问句题外话,程序中的handler中文名称是什么?处理器,还是处理程序?
    yibin001
        10
    yibin001  
    OP
       2014-05-27 11:16:56 +08:00   ❤️ 1
    @taine
    处理程序
    taine
        11
    taine  
       2014-05-27 12:06:29 +08:00
    @yibin001 谢谢!
    latyas
        12
    latyas  
       2015-07-14 11:03:30 +08:00   ❤️ 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()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2344 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:01 · PVG 23:01 · LAX 08:01 · JFK 11:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.