H C H C - 1 month ago 7
JSON Question

How to change to string and remove ' from Django tempalates / context?

I currently have a date that is formatted in unicode:

k = u'2015-02-01'


I tried to add this to a list and change it into a string:

date = []
date.append(str(k))


Then I want to pass this as a Django context to my template.

However, the date is showing up with the following:

'2015-02-01'


How do I just rid of $#39; and replace it with a double quote (")?

Thanks much.

Answer

You can try to prevent string escape in template like this:

{{ variable|safe }}

In-view way:

inescapable = Context({'data': data}, autoescape=False)