Reading list of values from django request object

Dec 13, 2016

Sometimes an array of values is sent as a param of a GET or POST request to the server. For example, when you have a multiple select or a group of check boxes in the front end, the form submission URL may look like this:

http://xyz.com/api_endpoint?selections%5B%5D=2

Use getlist to read this array of values in a django view function:

def my_view(request):
    ...
    selections = request.GET.getlist('selections[]')
    ...