yegle
yegle

Reputation: 5875

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

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

Upvotes: 10

Views: 9280

Answers (1)

Ben Hoyt
Ben Hoyt

Reputation: 11044

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?

Upvotes: 17

Related Questions