Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting the descriptions of a Radio Button Form
    primarykey
    data
    text
    <p>I have a list of tuples, that I get from a sqlite3 database. I have tried to get the database differently without any luck, this is not the person of this question but ultimately if it helps format the description of my radio button form I will be ecstatic.</p> <p>the list I have looks like:</p> <pre><code>images = [(1, u'True', u'file_Name.img', u'img', u'train', u'2013-02-0509:59:46.442660file.ext', u' file2.ext', u'ABC', u"[u'prod_one-prod_two']", u'name@email.com', u'nothing happens', u'2013-02-0509:59:46.442660', u"[u'ftp://link/file_Name.img', u'ftp://link/file3.ext', u'ftp://link/file_Name.log']"),(2, u'True',u'file_Name.img', u'img', u'train', u'2013-02-0509:59:46.442660file.ext', u' file2.ext', u'ABC', u"[u'prod_one-prod_two']", u'name@email.com', u'nothing happens', u'2013-02-0509:59:46.442660', u"[u'ftp://link/file_Name.img', 'ftp://link/file3.ext', u'ftp://link/file_Name.log']")] </code></pre> <p>What I would like to do is have the value of the selection be the first element of each tuple</p> <pre><code>rows = [(str(x[0]), x) for x in images] form.images.choices = rows </code></pre> <p>However it looks as if I just printed that mess with the unicode character and everything.</p> <p>So I am trying to format it in a nice table so it is easy to see what each tuple contains</p> <pre><code>descriptionList = [] description = '' for i in images: for j in i: description = description + '\t|' + str(j) descriptionList.append(description) rows = [(str(x[0]), y) for x, y in zip(images, descriptionList)] form.images.choices = rows </code></pre> <p>However it does not have the tab character in the output when I display the form.</p> <p>So now I am thinking about passing descriptionList into the template and display it beside each radio box to act as a description in the form.</p> <pre><code>return render_template('database.html', form=form, descriptions = descriptionList) {% for subfield, desc in zip(form.images, descriptions) %} &lt;tr&gt; &lt;td&gt;{{ subfield }}&lt;/td&gt; {# {{ subfield.label }} (this is a comment)#} desc &lt;br&gt; &lt;/tr&gt; {% endfor %} </code></pre> <p>However I get the error "UndefinedError: 'zip' is undefined"</p> <p>and without it I get:</p> <pre><code>{% for subfield, desc in (form.images, descriptions) %} ValueError: too many values to unpack </code></pre> <p>Any suggestions on how to solve this would be nothing short of amazing. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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