web.py: how to get POST parameter and GET parameter?

守給你的承諾、 提交于 2019-12-21 09:11:48

问题


I'm new to web.py. I used PHP alot. In PHP, POST parameter and GET parameter is stored in different global variables

For example:

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

In PHP you can get $_GET['get_param1'] is 1 and $_POST['post_param1'] is 2.

But it seems impossible to distinct GET/POST parameters in web.py?

I can only use web.input() to get GET/POST parameters in a dict-like object, but I cannot tell which of them is from the query string and which is from POST data


回答1:


There's actually an (undocumented?) _method parameter that can be get, post or both (the default) to return variables from the different sources. See the source for web.input(). So for example:

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

However, I've used web.py a lot, and never needed this. Why do you need to distinguish between input parameters in the query string and the data?



来源:https://stackoverflow.com/questions/10174738/web-py-how-to-get-post-parameter-and-get-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!