xenophon xenophon - 1 year ago 146
Python Question

Tornado templates setting value field

I have a python array:


I pass this as a value to tornado render:

self.render("index.html", a=a)

In my html I have the following:

<input type="hidden" id="xxx" value="
{% for c in a %}
{% end %}

Which gives me the following messy output:

<input type="hidden" id="xxx" value="








I tried to use a {{c.strip()}} but that did the same thing. I also trying to mix in javascript however the javascript didn't execute after rendering to populate the value field. I want the html to be normal that is
value="a b c d e f"

Does anyone know how I can achieve this?

Answer Source

Just join the list in the backend itself.

 self.render("index.html", a=' '.join(a))

And use,

<input type="hidden" id="xxx" value="{{ a }}" />

in template

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download