Skip to content
Myr

Rolled multi-value form examples in documentation into one (#4700)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

As suggested by @nateprewitt

authored by Antti Kaihola · committed by Antti Kaihola · parent 87fb312 · Browse files · 1 file+11 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−22 removed

  • other:+11 added−22 removed

1 file+11 added−22 removed

modified:docs/user/quickstart.rst+11 added-22 removed
242 unmodified lines
243 },244 ...245 }246247You can also pass a list of tuples to the ``data`` argument. This is particularly248useful when the form has multiple elements that use the same key::247The ``data`` argument can also have multiple values for each key. This can be248done by making ``data`` either a list of tuples or a dictionary with lists249as values. This is particularly useful when the form has multiple elements that250use the same key::251250 >>> payload = (('key1', 'value1'), ('key1', 'value2'))251 >>> r = requests.post('http://httpbin.org/post', data=payload)252 >>> print(r.text)252 >>> payload_tuples = [('key1', 'value1'), ('key1', 'value2')]253 >>> r1 = requests.post('http://httpbin.org/post', data=payload_tuples)254 >>> payload_dict = {'key1': ['value1', 'value2']}255 >>> r2 = requests.post('http://httpbin.org/post', data=payload_dict)256 >>> print(r1.text)257 {258 ...259 "form": {260 "key1": [
2 unmodified lines
263 ]264 },265 ...266 }267 >>> r1.text == r2.text268 True269264An alternative method to express multiple elements with the same key is to use265a dictionary and list the element values as a list::266267 >>> payload = {'key1': ['value1', 'value2']}268 >>> r = requests.post('http://httpbin.org/post', data=payload)269 >>> print(r.text)270 {271 ...272 "form": {273 "key1": [274 "value1",275 "value2"276 ]277 },278 ...279 }280270There are times that you may want to send data that is not form-encoded. If271you pass in a ``string`` instead of a ``dict``, that data will be posted directly.272273For example, the GitHub API v3 accepts JSON-Encoded POST/PATCH data::
291 unmodified lines