I run:
response.set_cookie(key, value=value, expires=expires, path=path, domain=domain)
When the value is: aa:aa
The cookie value is: "aa:aa"
When the value is: aa
The cookie value is: aa
I need to prevent django from adding quotes when there are colons in the value
When setting the value into cookie, just encode it using urllib.parse.quote_plus()
or urllib.parse.quote()
. e.g.
value = urllib.parse.quote_plus(value)
response.set_cookie(key, value=value, expires=expires, path=path, domain=domain)
And while getting value from cookie, decode it back using urllib.parse.unquote_plus()
or urllib.parse.unquote()
respectively. e.g.
if key in request.COOKIES:
value = urllib.parse.unquote_plus(request.COOKIES[key])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With