1

Possible Duplicate:
Django: Parse JSON in my template using Javascript

I'm trying to pass a Python data structure to javascript via a GAE/Django template and following the steps here. I'm getting an error that I can't figure out.

Here is the relevant excerpt of my Python GAE code:

class MyRequestHandler(webapp.RequestHandler):
    template_values = dict(
        data = json.dumps(dict(hello = "world"))
    )
    path = os.path.join(TPATH, 'template.html')
    self.response.out.write(template.render(path, template_values))

Here is the relevant excerpt from the Django template:

<script type="text/javascript">
var data = {{ data }};
</script>

This gives the error:

Invalid property id
var data = {&quot;hello&quot;: &quot;world&quot;};

Can you help me figure out what I am doing wrong?

EDIT:

As noted this is a duplicate and the fix is to do this.

<script type="text/javascript">
var data = {{ data|safe }};
</script>
Community
  • 1
  • 1
new name
  • 15,861
  • 19
  • 68
  • 114
  • @Proppy, you are right. Was searching for a wicked long time before asking my Q and didn't find that post. – new name Dec 10 '11 at 14:22

0 Answers0