I have a python dictionary e.g.:
[{"pk":"1","name":"John","size":"1/4" "},{},{},etc]
That size is 1/4 inch,how would I “escape” that quote? So it still would display it as 1/4″,
Its a list of things, so I cant just manually code it like 1/4\",
I tried replace('"','\"')
EDIT:
The orginal list is a textfield in my Django models:
[{'pk': '91', 'size': '', 'name': 'Thread Flat For BF', 'quantity': '2'}, {'pk': '90', 'size': '', 'name': 'Blade Holders Straight ', 'quantity': '26'},{'size':'3"','name':'2m 1/4" Round bar', 'quantity':'43'},{'size':'5','name':'2m 1/8" Round bar', 'quantity':'4'}]
Next step I have to prepare the list for jQuery, so I replace like this so its in the correct syntax for json.
mat_list = manufactured_part.material_list.replace(“‘”,'”‘)
Then I have this list:
[{"pk": "91", "size": "", "name": "Thread Flat For BF", "quantity": "2"}, {"pk": "90", "size": "", "name": "Blade Holders Straight ", "quantity": "26"},{"size':"3"","name':"2m 1/4" Round bar", "quantity":"43"},{"size":"5","name":"2m 1/8" Round bar", "quantity":"4"}]
So now the list is sent to the template and I loop through it with jquery, but the list is broken because of the ” in the strings.
SO…I need to escape those ” for the list to work, otherwise it has an obvious syntax error.
Hope this makes sense now.
Thanks
You need to escape your backslash in the replace in order to get it printed. Try