How to escape single quotes in Python on a server to be used in JavaScript on a client

How to escape single quotes in Python on a server to be used in JavaScript on a client

As a general solution for passing data from Python to Javascript, consider serializing it with the json library (part of the standard library in Python 2.6+).

>>> sample = helloworld
>>> import json
>>> print json.dumps(sample)
helloworld

Use:

sample.replace(, r)

or

sample.replace(, \)

How to escape single quotes in Python on a server to be used in JavaScript on a client

Leave a Reply

Your email address will not be published. Required fields are marked *