V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-10-23 17:22:09 +08:00 · 2656 次点击
    这是一个创建于 3843 天前的主题,其中的信息可能已经有所发展或是发生改变。
    是这样:一个接口接受到post请求后,经过简单处理,然后需要调用另一个接口的post方法。

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

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

    可以做到吗?
    2 条回复    1970-01-01 08:00:00 +08:00
    1989922yan
        1
    1989922yan  
       2013-10-23 21:19:56 +08:00
    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
       2013-10-23 22:02:16 +08:00
    @1989922yan 感谢回复。

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

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

    不知道有没有比较直接的接口调用接口的方法?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   773 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:49 · PVG 05:49 · LAX 14:49 · JFK 17:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.