Created
April 27, 2017 19:50
-
-
Save slinkp/26c0fa47c124552b774698e803e2913a to your computer and use it in GitHub Desktop.
django RequestFactory query param with multiple values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [3]: from django.test import RequestFactory | |
In [4]: rf = RequestFactory() | |
In [5]: req = rf.get('/foo', {'bar': ['baz', 'bat']}) | |
In [6]: req # this looks like expected: | |
Out[6]: <WSGIRequest: GET '/foo?bar=baz&bar=bat'> | |
In [7]: req.GET['bar'] # Why does this give me only one value? | |
Out[7]: u'bat' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Django took that decision a long time ago; I'm not sure on the history of it.
You can use
req.GET.getlist("bar")
instead, to achieve the goal in[7]
.