Answer the question
In order to leave comments, you need to log in
How to make friends request.COOKIES and nested json objects?
Hello, I have an unexpected problem, I can not find a solution, please tell me how to solve it.
I try to pick up cookies in the view. print(request.COOKIES)
Everything is fine, I get all the cookies, but if the cookie contains a nested json object, for example
var user = '{ "name": "Вася", "age": 35, "isAdmin": false, "friends": [0,1,2,3] }';
user = JSON.parse(user);
Answer the question
In order to leave comments, you need to log in
In [6]: c = json.loads('{ "name": "Вася", "age": 35, "isAdmin": false, "friends": [0,1,2,3] }')
In [7]: type(c['friends'])
Out[7]: builtins.list
In [8]: type(c['friends'])
Apparently, janga has nothing to do with it, you just write cookies incorrectly. How do you add json to a cookie on the JS side? The set of valid characters for a cookie value is limited. You can't put commas or special characters in them.
Use base64 encoding to save the json structure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question