Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Created July 5, 2017 15:45
Show Gist options
  • Save prodeveloper/37219d6d54f4e8b897bd956ebc845591 to your computer and use it in GitHub Desktop.
Save prodeveloper/37219d6d54f4e8b897bd956ebc845591 to your computer and use it in GitHub Desktop.
Working with loops in the template

So far, we have been able to successfully retreive and display a single entry from the database.

In today’s lesson, we will be looking at how we can show multiple records. In this case, all the students that we have listed.

##Step 1

We start by retrieving the list of all students from the database and putting the data in the context.

This will now allow us to be able to use the students variable from our template

##Step 2

We will now modify the listing on the template to show the information. Modify the body tag of your listing_students.html template to now loop over and show the names.

Note the use of {%%} tags to represent constructs and {{}} to print out data from the variables.

When you run the project, you should see the list of all names in the database as follows

##Step 3

In most cases we will need to show more than just the names, we will need to show all the information.

In such cases, it makes sense to display the information in a table such as

This is a bit more complex than our normal html. This is to ensure our table looks relatively good.

##Assignment

To the table created in the lesson. Add the attributes for the Date of Registration

##Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment