← flask-blog

for loop / jinja2

d092d4ea68fda58a8867c5f80d70ef7ec5a26d9a · ovidiucs · May 12, 2015 19:37

+34 · 2 files changed

  • flask-blog.py +7 −0
  • templates/weather-average.html +27 −0
diff --git a/flask-blog.py b/flask-blog.py
index 87ae9d2..bc827aa 100644
--- a/flask-blog.py
+++ b/flask-blog.py
@@ -11,6 +11,13 @@ def hello_world():
 def user(name):
     return render_template('user.html',name=name)
 
+@app.route('/jin2/loop')
+def index():
+    months = ['January','February','March','April','May','June','July',
+              'August','September','October','November','December']
+
+    return render_template('weather-average.html',city='Portland, OR',
+                           months=months)
 
 if __name__ == '__main__':
     app.run(debug=True)
diff --git a/templates/weather-average.html b/templates/weather-average.html
new file mode 100644
index 0000000..9e28555
--- /dev/null
+++ b/templates/weather-average.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head lang="en">
+    <meta charset="UTF-8">
+    <title></title>
+</head>
+<body>
+    <h2>{{ city }}</h2>
+    <hr>
+    <table>
+        <tr>
+            <th>Month</th>
+            <th>Min</th>
+            <th>Max</th>
+            <th>Rainfall</th>
+        </tr>
+        {% for month in months %}
+        <tr>
+            <td>{{ month }}</td>
+            <td></td>
+            <td></td>
+            <td></td>
+        </tr>
+        {% endfor %}
+    </table>
+</body>
+</html>
\ No newline at end of file