【问题标题】:web.py: how to get POST parameter and GET parameter?web.py:如何获取 POST 参数和 GET 参数?
【发布时间】:2012-04-27 19:39:32
【问题描述】:

我是web.py 的新手。我经常使用 PHP。在 PHP 中,POST 参数和 GET 参数存储在不同的全局变量中

例如:

curl http://127.0.0.1/test?get_param1=1 -d 'post_param1=2'

在 PHP 中,您可以得到 $_GET['get_param1'] 为 1,$_POST['post_param1'] 为 2。

但似乎不可能区分web.py 中的 GET/POST 参数?

我只能使用web.input() 来获取类似dict 的对象中的GET/POST 参数,但我不知道它们中哪些来自查询字符串,哪些来自POST 数据

【问题讨论】:

    标签: python web web.py


    【解决方案1】:

    实际上有一个(未记录的?)_method 参数可以是getpostboth(默认值)来返回来自不同来源的变量。 See the source for web.input(). 比如:

    get_input = web.input(_method='get')
    post_input = web.input(_method='post')
    

    但是,我使用 web.py 很多,从来不需要这个。为什么需要区分查询字符串中的输入参数和数据?

    【讨论】:

    • 只是想知道这是否有效或有帮助?如果是这样,请将答案标记为已接受或分别投票。
    猜你喜欢
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 2013-05-13
    相关资源
    最近更新 更多