ChrisRob
ChrisRob

Reputation: 1552

Django Capturing multiple url parameters in request.GET

i am trying to get all query parameters out of an request

url/?animal__in=dog,cat&countries__in=france

I tried

animals = request.GET.get('animal__in','')
countries = request.GET.get('countries__in','')

but then animals and countries are not lists, they are just strings. Is there a more django way to do this whole capturing?

Edit: Its important that i am using it in django-admin for filtering, where these two are not the same:

url/?animal__in=dog,cat&countries__in=france
url/?animal__in=dog&animal__in=cat&countries__in=france

Upvotes: 0

Views: 1377

Answers (3)

ChrisRob
ChrisRob

Reputation: 1552

split(',') works fine, not really django though

animals = request.GET.get('animal__in','').split(',')
countries = request.GET.get('countries__in','').split(',')

Upvotes: 1

sebb
sebb

Reputation: 1966

request.GET.getlist('some_list_field')

Upvotes: 2

Daniel Roseman
Daniel Roseman

Reputation: 599450

Send the parameters in the proper HTTP format:

?animal__in=dog&animal__in=cat&countries__in=france

and do

request.GET.getlist('animal__in')

Upvotes: 1

Related Questions