推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
laomo
V2EX  ›  Python

[webpy问题]一个接口可以直接调用另一个接口的post方法吗?

  •  
  •   laomo · Oct 23, 2013 · 3335 views
    This topic created in 4720 days ago, the information mentioned may be changed or developed.
    是这样:一个接口接受到post请求后,经过简单处理,然后需要调用另一个接口的post方法。

    如果没有参数,可以通过url匹配规则,直接用web.seeother(path)

    现在问题是有参数,参数可以认为是个元组或者列表。

    可以做到吗?
    2 replies  •  1970-01-01 08:00:00 +08:00
    1989922yan
        1
    1989922yan  
       Oct 23, 2013
    1. [不确定]
    不知道能不能通过web.seeother(path?argv=value)
    这样的方法传参数过去。

    另一个函数使用:web.input()获取这个参数。

    2. [确定]
    假如存在 A 和 B 两个接口。
    A 调用 B 的 POST() 的方法。

    ——B.py——
    def uWant():
    ....pass

    class B:
    ....def POST(self):
    ........uWant()


    ——A.py——
    import B

    class A:
    ....def POST(self):
    ........B.uWant()

    不知道这样是不是你想法。
    laomo
        2
    laomo  
    OP
       Oct 23, 2013
    @1989922yan 感谢回复。

    方法一可行,如果参数觉少,可以这样,现在是参数比较多,并且都是url

    提完问题已经改成你所说的方法二这种实现。之所有想接口调用接口,就是想代码复用,其实换个思路,把代码直接抽成一个方法就好了。

    不知道有没有比较直接的接口调用接口的方法?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2570 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:44 · PVG 20:44 · LAX 05:44 · JFK 08:44
    ♥ Do have faith in what you're doing.