python - Weird session object behavior in django -
I try to apply a simple train using a dictionary
{ITEM_ID: quantity} I have been a list of items {{ID: Quantity}} dajax I did not use any thing as a try, as mentioned in the document, I received a very strange result request.session.modified Note: I explicitly rounded up the ITEM_ID, so I do not know Where is the string key coming from! Note: The cart object does not hold more than 4 keys! The default syntax is JSON format used by sessions JSON Only allows the key in the form of a string, so when the data is saved in the database, all the integer keys are converted into a string. When you load the data, the fact that they have lost the integer, and the keys are plain strings (well, unicode wire). The simplest solution is to use the string in particular in its session data keys, and only convert it to the integer for the further process.
Cart: {u'1 ' : 1, 1: 1, u'3 ': 1, u'2': 1}
Comments
Post a Comment