1👍
✅
The u-prefix just means that you have a Unicode string. When you really use the string, it won’t appear in your data.
If you really wish to convert it to normal string you can convert both key and value using dictionary comprehension and str
keyword.:
data_from_angular = dict((str(k), str(v)) for k, v in data_from_angular.items())
0👍
I think this should work
data_from_angular = json.loads(request.body.decode("utf-8"))
another_dict = dict()
for k, v in data_from_angular.iteritems():
if v.isdigit():
another_dict[k] = v
elif v.isalpha():
another_dict[k] = v
else:
# do something here
I prefer this than clever oneliners because after six months down the lane one fool is gonna look into that code and ask what this oneliner doing here..? And that fool could be anyone in including yourself!
This is drawn from y personal experience
- Django 1.10 – how to load initial users
- Where should I place the login and logout in Django?
- Django – Pass a jQuery array as url argument
Source:stackexchange.com