Response JSON Quoting

5 views
Skip to first unread message

Szaijan

unread,
Apr 17, 2008, 12:57:58 AM4/17/08
to Django users
I had my first Django app running on the dev server, but in gettting
mod-python installed and running I seem to have broken something... or
fixed something that was broken before.

Previously, when I'd send a response dictionary object from a view, I
would include a field called queryJson which held a simplejson.dumps
output of a JSON object with all the database information needed for
needed for my Javascript.

The output looked something like:

{'success': 'true',
'queriesJson' : "{'objects': \"{'objId': \"{\"pk\":1,...}\"}\" }"}

After installing mod_python 3.3.1, reinstalling Django 0.96 (from svn
trunk), and reinstalling psycopg2 2.0.5.1, the quoting is all screwed
up and my Javascript no longer functions. What comes through now is
the same as above, but all of the quotes are replaced with """,
and the backslash escapes all remain.

{"success": "true",
"queriesJson" : "{"objects": \"
{"objId": \"{\"pk\":1,...}\"}
\" }"}

Javascript eval is unable to parse this. Any ideas on what could be
causing this?

Everything else runs fine. My views access the database flawlessly
and simplejson.dumps produces the same output as before. Only the
template's expression of that output has changed.

Justin Bronn

unread,
Apr 17, 2008, 1:35:23 AM4/17/08
to Django users
> After installing mod_python 3.3.1, reinstalling Django 0.96 (from svn
> trunk), and reinstalling psycopg2 2.0.5.1, the quoting is all screwed
> up and my Javascript no longer functions.

Are you sure pulled 0.96 from the svn? Auto-escaping has been in
trunk for 5 months now (r6671).

-Justin

Malcolm Tredinnick

unread,
Apr 17, 2008, 1:38:40 AM4/17/08
to django...@googlegroups.com

On Wed, 2008-04-16 at 21:57 -0700, Szaijan wrote:
[...]

> After installing mod_python 3.3.1, reinstalling Django 0.96 (from svn
> trunk),

Subversion trunk isn't Django 0.96. It's Django 0.96 plus almost a
year's worth of changes.

> and reinstalling psycopg2 2.0.5.1, the quoting is all screwed
> up and my Javascript no longer functions. What comes through now is
> the same as above, but all of the quotes are replaced with """,
> and the backslash escapes all remain.
>
> {"success": "true",
> "queriesJson" : "{"objects": \"
> {"objId": \"{\"pk\":1,...}\"}
> \" }"}

Because you upgraded your Django code to something much later than your
development version, you've picked up all the changes in the interim,
including the autoescaping change.

So either make sure you are using a Django 0.96.1 tarball (0.96.1 is
0.96 plus a security fix) or read the BackwardsIncompatibleChanges page
in the wiki to see all the changes that may or may not affect your code.

Regards,
Malcolm

--
If at first you don't succeed, destroy all evidence that you tried.
http://www.pointy-stick.com/blog/

Szaijan

unread,
Apr 17, 2008, 1:42:37 AM4/17/08
to Django users
Thanks Justin. Yes, I'm certain. And my previous install was also
some variety of 0.96, though I downloaded that one manually.

In any case, the " escape outputs to screen just fine, but I get
a parse error any time I try to use it in my javascript. It would be
nice if there was a built in 'unescape' filter to go with the escape
filter. I just don't understand why I need it now and didn't before.
When I configured Django the first time I must have turned off auto-
escaping, but I can't seem to find a way to do that now.

Darryl Ross

unread,
Apr 17, 2008, 7:46:41 PM4/17/08
to django...@googlegroups.com
Szaijan wrote:
> Thanks Justin. Yes, I'm certain. And my previous install was also
> some variety of 0.96, though I downloaded that one manually.

What was the complete SVN URL you used? You can get it with 'svn info'
in the directory you checked out the Django code to.

Regards
Darryl

signature.asc
Reply all
Reply to author
Forward
0 new messages