Reputation: 45
After form submit I am getting data like this. Now I want to insert this data by the loop in a model or in the table using a for loop.
{'user_id': ['4'],
'type': ['1'],
'csrfmiddlewaretoken': ['Umvdq9BhNUNg94XZNDwkzXfhbjwZY91vKfyqsgBsGAXeRG9NS2DAB87Jvgv3NQlx'],
'vehicle_no[]': ['ertere', '11', '2222'],
'mileage[]': ['eere', '111', '2222'],
'vehicle_category[]': ['1', '1', '1'],
'status[]': ['2', '2', '2']
}
After this, I am doing this to get the data:
for k,v in vals:
print(vals)
to get values so I can insert it into DB with multiplke
rows, but when I am doing the same I am getting the following error:
too many values to unpack (expected 2)
I am stuck here. If anyone has an idea please share or solve my issue.
Upvotes: 0
Views: 72
Reputation: 373
What you are printing is the whole dictionary in place of key and value pair. try using:
for k,v in vals.items():
print([k,v])
Also, Since you are not changing data from the form, to make things easier, you might consider using the Django forms, it will make things a lot easier for you.
Upvotes: 1