The example code you provided will create a <tr> on the first iteration of the loop and </tr> tag every 4th iteration of the loop. This cycle will continue resulting in a table with 4 columns of data. Example:
results = [ 1, 2, 3, 4, 5, 6, 7, 8 ] <table> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr></table> If you have 2 lists, render them from your view like return render(request, 'polls/detail.html', {'list1': list1, 'list2': list2}) In your template create an 8 column table: <table> {% for r in list1 %} {% cycle '<tr>' '' '' '' '' '' '' ''%} <td>{{r}}</td> {% cycle '' '' '' '' '' '' '' '</tr>' %} {% endfor %} {% for r in list2 %} {% cycle '<tr>' '' '' '' '' '' '' ''%} <td>{{r}}</td> {% cycle '' '' '' '' '' '' '' '</tr>' %} {% endfor %} </table> Hope this helps On Friday, June 21, 2019 at 5:58:21 PM UTC-5, Sudeep Gopal wrote: > > Hello, > > I am new to django. > > I am using django forms in my project and I am not using django models. > > From the user, my django form asks for 4 inputs :- signal_to_noise_1 , > signal_to_noise_2, bandwidth1 and bandwidth2. > > Based on these values I use my look up table and I create a results which > are 2 lists of records. > Each list has approximately 40 to 50 records. Each record has 8 fields. > (field1,...field8) ... > > *Each list *looks like this (if my description is not clear) field1 is > unique. > > field1 field2 field3 > > > > field8 > > > > > > > > > > > > Both the lists (with each list having about 50 records) are in my django > view. > > From what I read online, I can use the render() method which has a > *dictionary > *called context. ( > https://docs.djangoproject.com/en/2.2/ref/templates/api/#rendering-a-context > <https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.2%2Fref%2Ftemplates%2Fapi%2F%23rendering-a-context&sa=D&sntz=1&usg=AFQjCNFeyvWxqdh2HVrALIVw53ScRw4SVw> > ) > > I am not sure how to convert these list of record objects to this > dictionary format which has {"name":value} pair. > > Even the django tables requires it in the dictionary format..... > > The nearest thing which I found was > https://stackoverflow.com/questions/9388064/django-template-turn-array-into-html-table > > > But I did not understand what exactly the below syntax does and how I can > customize it to my usecase ....any input would be greatly appreciated ... > > <table> > {% for r in results %} > {% cycle '<tr>' '' '' '' %} > <td>{{r.content}}</td> > {% cycle '' '' '' '</tr>' %} > {% endfor %}</table> > > > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/600c0fd5-8682-493e-ba8e-4c2cdba31776%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.