2

on server sends this data:

Object { categoryes: Array[2], brands: Array[2], discount_list: "all", category_slug: "accessories", category_of_relationsheep: "m" }

if i print request.POST in server side i got this:

<QueryDict: {'categoryes[]': ['Accessories', 'Bands'], 'brands[]': ['Nike', 'HBO'], 'discount_list': ['all'], 'csrfmiddlewaretoken': ['S7MXVEdQLd6u0fr4FugEwlupa45oChmw3TeItB4BEUHUHSsxrmVRuAcAhFxYQfpk'], 'category_slug': ['accessories'], 'category_of_relationsheep': ['m']}>

hot i can get a list for example "categoryes[]" (but why it called like this with brackets?)

ok if i do like this: print(request.POST.get("categoryes[]")) it will give the only last object,

how to get full list? specific like cotegoryes? if make like

for keys, values in request.POST.items():
    print(values)

it print me all values in this dict, but i don't know from where this values? if i make this:

for keys, values in request.POST.items():
        if 'categoryes[]' == keys:
            print(values)

it give the same only one object related to categoryes but in this list more than 1 object

2 Answers 2

5

Try using getlist

request.POST.getlist('categoryes[]')
Sign up to request clarification or add additional context in comments.

Comments

1

When accessing request.GET and request.POST, you don't get a regular dictionary, you get a QueryDict object. When accessed as a dictionary, it returns the last value for a key. If you want the full list, use the getlist method, for instance:

request.POST.getlist("somekey")

Returns a list of the data with the requested key.

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.