javascript - Get JSON object from server-side Python into client-side Django template -
server-side, in python, i'm returning json object looks this:
contactaddr = {'name' : name, …} contactaddrjson = json.dumps(contactaddr)
client side, i'm using django's template engine dump string javascript variable, , turning object this:
var _myaddressobj = '{{ contactaddrjson|safe}}'; var adrobj = $.parsejson(_myaddressobj);
this worked fine, until got name had single-quote in it. i've spent past couple of hours trying figure out these levels of string escapes damn object javascript, no avail. need robust single , double quotes. can enlighten me? brain smoking.
you can skip parsing process. json data syntactically valid javascript, can put directly source:
var adrobj = {{ contactaddrjson|safe}};
Comments
Post a Comment