3

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.

H C
  • 1,138
  • 4
  • 21
  • 39

3 Answers3

12

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

{{ variable|safe }}

In-view way:

from django.utils.safestring import mark_safe
from django.template import Context
data=mark_safe(data) 
inescapable = Context({'data': data}, autoescape=False)
Anatoly Strashkevich
  • 1,834
  • 4
  • 16
  • 32
0

I know this is old but other people might stumble upon this with the same problem

Try

{% autoscape off %} {{ date }} {% endautoscape %}

It worked fine for me

0

When requesting graphs from google charts the data must be sent as a text array. The csv file has to be pure text with no apostrophes. however code fragment data = repr(textData) returns data bounded by ' ' this is interpreted as "&#39" in html

The solution to this is to javascript split method var par = textData.split(""&#39") textArray = par[1] // the part without ' rest of code

pmr
  • 1