On Thu, May 15, 2008 at 12:29 PM, Chris Farley <[EMAIL PROTECTED]> wrote:
> My Django app needs to read a cookie that is written by a JavaScript
> script in another part of my website. The JavaScript code that
> generates the cookie is something like this:
>
> document.cookie='ShoppingCart=[7008|2][7120|3]; path=/;
> domain=mydomain.com';
>
> I can see the cookie and its content from Firefox and Safari when I
> "view cookies". Django's request.COOKIES dictionary contains a key for
> the 'ShoppingCart' cookie, but the content is always an empty string.
>
> Is this a feature or a bug?

I'm not sure if it's a feature or a bug, but it's certainly not
Django's doing. If you try the following in a Python shell, you'll see
that this behavior is part of Python's own cookie handling.

>>> from Cookie import SimpleCookie
>>> SimpleCookie('ShoppingCart=[7008|2][7120|3]; path=/; domain=mydomain.com')
<SimpleCookie: ShoppingCart=''>

But, if you quote the cookie's value ...

>>> SimpleCookie('ShoppingCart="[7008|2][7120|3]"; path=/; domain=mydomain.com')
<SimpleCookie: ShoppingCart='[7008|2][7120|3]'>

I don't know if it'd be easier for you to quote the value or just
avoid square brackets (since that's where SimpleCookie seems to
choke), but it looks like it should be easy enough to work around.

-Gul

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to