Jinja2 Mastery: Level 1: What are Jinja2 tests? (+22, -1)

app.py (+7, -0)

From: curriculum/section09/lectures/08_jinja2_tests/start/app.py

To: curriculum/section09/lectures/08_jinja2_tests/end/app.py

            
            index 81d77d4..d183a9a 100644
--- a/curriculum/section09/lectures/08_jinja2_tests/start/app.py
+++ b/curriculum/section09/lectures/08_jinja2_tests/end/app.py
@@ -4,6 +4,13 @@ from flask import Flask, render_template
 app = Flask(__name__)
 
 
+def divisibleby(value, other):
+    return value % other == 0
+
+
+app.jinja_env.tests["divisibleby"] = divisibleby
+
+
 @app.route("/")
 def todo():
     return render_template("fizzbuzz.html")
        

fizzbuzz.html (+15, -1)

From: curriculum/section09/lectures/08_jinja2_tests/start/templates/fizzbuzz.html

To: curriculum/section09/lectures/08_jinja2_tests/end/templates/fizzbuzz.html

            
            index 466e994..53dc63e 100644
--- a/curriculum/section09/lectures/08_jinja2_tests/start/templates/fizzbuzz.html
+++ b/curriculum/section09/lectures/08_jinja2_tests/end/templates/fizzbuzz.html
@@ -7,6 +7,20 @@
   <title>Fizzbuzz</title>
 </head>
 <body>
-  
+  <ul>
+    {% for n in range(1, 101) %}
+    <li>
+      {% if n is divisibleby(3) and n is divisibleby(5) %}
+        FizzBuzz
+      {% elif n is divisibleby(3) %}
+        Fizz
+      {% elif n is divisibleby(5) %}
+        Buzz
+      {% else %}
+        {{ n }}
+      {% endif %}
+    </li>
+    {% endfor %}
+  </ul>
 </body>
 </html>