D
D
DarkByte20152017-09-08 19:39:05
Django
DarkByte2015, 2017-09-08 19:39:05

How to get normal dictionary from QueryDict?

The following data is sent from the front in js ajax:

{
    'cart': [
        {
            'id': 1,
            'count': 2
        }
    ]
}

But on the backend they come to the view in this form (or perhaps they are parsed like this): Please tell me how to bring them to a normal dictionary (in the same form in which they were sent)? I tried a lot of ways, rummaged through the whole Google. No working way. :(
{'cart[0][count]': ['2'], 'cart[0][id]': ['1']}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DarkByte2015, 2017-09-08
@DarkByte2015

No longer relevant - figured it out. The problem was in the front (the data went not in json, but in form-urlencoded).

A
Astrohas, 2017-09-08
@Astrohas

astrohas = dict(query_dict.iterlists())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question