← flask-blog

using the url_for for link generation

187441041904d9619c4732f3c74d555060a22237 · ovidiucs · May 12, 2015 21:28

+27 −1 · 3 files changed

  • flask-blog.py +3 −1
  • templates/404.html +9 −0
  • templates/base.html +15 −0
diff --git a/flask-blog.py b/flask-blog.py
index 18971d4..da5fbcc 100644
--- a/flask-blog.py
+++ b/flask-blog.py
@@ -39,7 +39,9 @@ def index():
 
     return render_template('weather-average.html', city='Portland, OR',
                            months=months, weather=weather, highlight=highlight)
-
+@app.errorhandler(404)
+def not_found(e):
+    return render_template('404.html')
 
 if __name__ == '__main__':
     app.run(debug=True)
diff --git a/templates/404.html b/templates/404.html
new file mode 100644
index 0000000..b97959c
--- /dev/null
+++ b/templates/404.html
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% import 'macros.html' as macros %}
+
+{% block title  %}Not Found{% endblock %}
+
+{% block page_content %}
+   <h1>Not Found</h1>
+    <p><a href = "{{ url_for('index') }}">Return to home page</a></p>
+{% endblock %}
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
new file mode 100644
index 0000000..af4b320
--- /dev/null
+++ b/templates/base.html
@@ -0,0 +1,15 @@
+{% extends 'bootstrap/base.html' %}
+
+{% block navbar %}
+    <nav class="navbar navbar-inverse" role="navigation">
+        <div class="container">
+            <a class="navbar-brand" href="{{ url_for("index") }}">Weather</a>
+        </div>
+    </nav>
+{% endblock %}
+
+{% block content %}
+    <div class="container">
+        {% block page_content %}{% endblock %}
+    </div>
+{% endblock %}
\ No newline at end of file