15 – HOW TO LIST ITEMS IN A TABLE IN DJANGO

Spread the love

1. Open computer_list.html add class to the h1 tag of the title

    <table class='table'>
        <thead>
          <tr>
            <th>COUNT</th>
            <th>CATEGORY</th>
            <th>ITEM NAME</th>
            <th>QUANTITY IN STORE</th>
          </tr>
        </thead>
      {% for instance in queryset %}
          <tr>
            <td>{{forloop.counter}}</td>
            <td>{{instance.category}}</td>
            <td>{{instance.item_name}}</td>
            <td>{{instance.quantity}}</td>
          </tr>
      {% endfor %}
    </table>

2. Open stylesheet.css
Update it with the following codes:

/*Align the title to the center of the page*/
.table{
	font-size: 13px;
	text-align: center;
	width: 95%;
	margin: auto;
	text-align: center;
}

/*Make alternating colors for the table rows*/
.table tr:nth-child(odd){
	background: #B8CAE4
}

.table tr:nth-child(even){
	background: #dae5f4
}

th {
  background-color: #337ab7;
  color: white;
}

3. Create a <div> element to style the table container

    <div class="display_table">
      <table>
      </table
    </div><!--End of display table-->

4. Style the <div> element

.display_table{
	border-bottom-right-radius: 20px;
	/*border-bottom-left-radius: 20px;*/
	padding-left: 5px;
	padding-right: 5px;
	padding-bottom: 20px;
	box-shadow: 12px 12px 20px 6px #2e6da4;
}

5. Style the header text

<div class="header"{{header}}</div>
.header {
    font-family: helvetica;
    color: #337ab7;
    font-size: 50px;
    text-align: center;
    width: 100%;
    text-shadow: 6px 6px 6px #c9c6c6;
    display: block;
    font-weight: bolder;
}

6. Save and refresh the computer_list page


Spread the love

About the author

arbadjie

Hi, I'm Abdourahman Badjie, an aspiring developer with obsession for anything coding and networking. This blog is dedicated to helping people learn to develop web applications using django framework.

View all posts

11 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *