1👍
✅
Your POST
data is really weird but for the sake of correctness, you should do:
first_name = post_data["user_data[first_name]"]
name_last = post_data["user_data[name_last]"]
Because the string user_data[first_name]
is the key for the dict not just string user_data
.
Edit:
If you want to convert user data into dict, you should loop on request.POST
and check for keys that contains user_data
keyword:
user_data = {}
for key, value in request.POST.iteritems():
if 'user_data' in key:
field = key.split('[')[1].replace(']', '')
user_data[key] = value
# convert into json
json_user_data = json.dumps(user_data)
Source:stackexchange.com