Skip to content

Instantly share code, notes, and snippets.

@slinkp
Created April 27, 2017 19:50
Show Gist options
  • Save slinkp/26c0fa47c124552b774698e803e2913a to your computer and use it in GitHub Desktop.
Save slinkp/26c0fa47c124552b774698e803e2913a to your computer and use it in GitHub Desktop.
django RequestFactory query param with multiple values
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'
@djm
Copy link

djm commented Jul 13, 2020

Why does this give me only one value?

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].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment