How to used for loop to create table in django form

user6315578

I wish to have the following table :

Brand  Total  Price
  A      2      2
  T      4      9
  I      2      20
  B      9      9
Total    17     40

while Brand=['A','T','I','B'];Total=[2,4,2,9] and Price=[2,9,20,9]

views.py

context['LUnique'] = range(1,LUnique+1)

Header.html

<div class="col-sm-3">
    <table class="table table-bordered " border="1">
        <tr>
            <td colspan="4">JUSON Supermart</td>
        </tr>
        {% for i in LUnique %}
            <tr>
                <td>{{i.Brand|safe}}</td>
                <td>{{i.Total|safe}}</td>
                <td>{{i.Price|safe}}</td>
            </tr>
        {% endfor %}
    </table>
</div>

Anyone can help me on this because above code not return the table as i wish.

Thiago Rossener

First, aggregate all the three lists into tuples using zip function.

views.py

Brand = ['A', 'T', 'I', 'B']
Total = [2, 4, 2, 9]
Price = [2, 9, 20, 9]

context = {'LUnique': zip(Brand, Total, Price)}

Then, iterate over it.

header.html

<div class="col-sm-3">
    <table class="table table-bordered " border="1">
        <tr><td colspan="4">JUSON Supermart</td></tr>
        {% for b, t, p in LUnique %}
            <tr>
                <td>{{b}}</td>
                <td>{{t}}</td>
                <td>{{p}}</td>
            </tr>
        {% endfor %}</table>
</div>

Result:

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create update form in a for loop?

From Dev

How to create a table using a loop?

From Dev

How to create a table using a loop?

From Dev

How I could create a table model with closure put multiple variable form loop

From Dev

How to view query that was used to create a table?

From Dev

How to create common method used in Web form as well as Windows form

From Dev

Create loop to change background color in table form Access 2007

From Dev

How to create a table in a form in Visual Studio

From Dev

How to create a table in a form in Visual Studio

From Dev

Django form how to create a simple mixin

From Dev

How to create Django form for a photo grid?

From Dev

How to create a profile registration form in Django?

From Dev

How to form a table with variable columns in Django Template

From Dev

How to create new table cells with loop?

From Dev

How to do double loop and create table?

From Dev

How to create new table cells with loop?

From Dev

How to create objects that can be used by multiple methods in form

From Dev

How to create objects that can be used by multiple methods in form

From Dev

How to use django loop {% %} to create multiple<div>

From Dev

How to break loop in shell script used to truncate table?

From Dev

How to DRY (myself) in Django form for Create and Edit Form

From Dev

how can I get the sql statements used to create a specific table?

From Dev

Django - How include() can be used to create plug and play URLs?

From Dev

django create custom form

From Dev

Nested 'for' Loop to Create Table

From Dev

Create Table with Loop in SAS

From Dev

How to create HTML valid table with form inside rows

From Dev

How to create HTML valid table with form inside rows

From Dev

How to add css in django Updateview or Create view form

Related Related

  1. 1

    How to create update form in a for loop?

  2. 2

    How to create a table using a loop?

  3. 3

    How to create a table using a loop?

  4. 4

    How I could create a table model with closure put multiple variable form loop

  5. 5

    How to view query that was used to create a table?

  6. 6

    How to create common method used in Web form as well as Windows form

  7. 7

    Create loop to change background color in table form Access 2007

  8. 8

    How to create a table in a form in Visual Studio

  9. 9

    How to create a table in a form in Visual Studio

  10. 10

    Django form how to create a simple mixin

  11. 11

    How to create Django form for a photo grid?

  12. 12

    How to create a profile registration form in Django?

  13. 13

    How to form a table with variable columns in Django Template

  14. 14

    How to create new table cells with loop?

  15. 15

    How to do double loop and create table?

  16. 16

    How to create new table cells with loop?

  17. 17

    How to create objects that can be used by multiple methods in form

  18. 18

    How to create objects that can be used by multiple methods in form

  19. 19

    How to use django loop {% %} to create multiple<div>

  20. 20

    How to break loop in shell script used to truncate table?

  21. 21

    How to DRY (myself) in Django form for Create and Edit Form

  22. 22

    how can I get the sql statements used to create a specific table?

  23. 23

    Django - How include() can be used to create plug and play URLs?

  24. 24

    django create custom form

  25. 25

    Nested 'for' Loop to Create Table

  26. 26

    Create Table with Loop in SAS

  27. 27

    How to create HTML valid table with form inside rows

  28. 28

    How to create HTML valid table with form inside rows

  29. 29

    How to add css in django Updateview or Create view form

HotTag

Archive