0

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

3 Answers 3

2

request.GET.getlist('some_list_field')

Sign up to request clarification or add additional context in comments.

Comments

1

Send the parameters in the proper HTTP format:

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

and do

request.GET.getlist('animal__in')

1 Comment

I want to use it as a filter in django-admin: So when i try this, it is the same like: ?animal__in=cat&countries__in=france
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.