Exercise 2.4E JSON Data Driven Loops (Nav, Professional, Service)

Purpose: Make the site data-driven rather than static. By making and passing JSON data, the code of the templates becomes simpler, smaller, and less repetitive than before.

Step 1. Create JSON Files

Create the following JSON data files:

Step 2. Make the Server Load JSON Files

Modify app.py so it loads these JSON files and passes a Python data structure to the Jinja templates for all routes where the information is used. All routes should use the nav, but the /professionals and /services routes should be the only ones that need to use the professionals and services data.

Step 3. Make the Templates Use the Data

Add Jinja {% for %} and {% endfor %} blocks to all templates where the information is used so that the display comes from the JSON data. The Services page should use two levels of {% for %} blocks.

Test your Project

By the end of this step, your project should work, delivering the same content as Project Part 1.