Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop in dictionary in HTML
    text
    copied!<p>I have a Python script creating a dictionary and passing it to a html page to generate a report.</p> <p>in Python:</p> <pre><code>data_query= {} data_query["service1"] = "value1" data_query["service2"] = "value2" return data_query </code></pre> <p>in HTML:</p> <pre><code>% for name, count in data_query: &lt;tr&gt; &lt;td&gt;${name}&lt;/td&gt; &lt;td&gt;${count}&lt;/td&gt; &lt;/tr&gt; % endfor </code></pre> <p>it does not work, says that it does not return enough values.</p> <p>I also tried (pointed out in a comment in the other question, that I deleted by mistake):</p> <pre><code>% for name, count in dict.iteritems(): </code></pre> <p>It does not give any error, but does not work. Displays nothing. </p> <pre><code>${len(dict)} </code></pre> <p>gives the right dictionary length</p> <pre><code>${len(dict.iteritems())} </code></pre> <p>does not display anything and seem to have a weird effect on my table format.</p> <p>Is there a way to iterate correctly a dictionart in HTMl to display both the key and value?</p> <p>EDIT: How I transfer the dictionary to the html page.</p> <pre><code>from mako.lookup import TemplateLookup from mako.runtime import Context from mako.exceptions import text_error_template html_lookup = TemplateLookup(directories=[os.path.join(self.dir_name)]) html_template = html_lookup.get_template('/templates/report.html') html_data = { 'data_queries' : data_queries } html_ctx = Context(html_file, **html_data) try: html_template.render_context(html_ctx) except: print text_error_template().render(full=False) html_file.close() return html_file.close() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload