R
R
redduckrobot2015-12-10 21:22:04
JavaScript
redduckrobot, 2015-12-10 21:22:04

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);

then django simply does not see this cookie. Is there any way to make friends with them?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2015-12-10
@sim3x

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'])

S
some1else, 2015-12-21
@some1else

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 question

Ask a Question

731 491 924 answers to any question