Skip to content

Commit v0.11

kwmccabe edited this page Apr 17, 2018 · 9 revisions

v0.11 - utils.flashed_messages() added to base.html, 403.html, 404.html, 410.html


Files changed (5)

File web/app/main/templates/base.html MODIFIED

  • Import template macro file bootstrap/utils.html.
  • Wrap utils.flashed_messages() in <div id="messages" />.
 {% extends "bootstrap/base.html" %}
+{% import "bootstrap/utils.html" as utils %} 

...

     <hr id="header_hr" size="1"/>
     {% endblock %}

+    <div id="messages" class="container-fluid flashed-messages">
+        <div class="row">
+            <div class="col-md-12">
+                {{ utils.flashed_messages(container=False, dismissible=True) }}
+            </div>
+        </div>
+    </div>

File web/app/templates/403.html ADDED

  • Display 403: Forbidden error within template base.html.
+{% extends "base.html" %}
+
+{% block title %}403: Forbidden{% endblock %}
+
+{% block content %}
+    <h1>Forbidden</h1>
+    <p>{{ error }}</p>
+{% endblock %}

File web/app/templates/404.html ADDED

  • Display 404: Page Not Found error within template base.html.
+{% extends "base.html" %}
+
+{% block title %}404: Page Not Found{% endblock %}
+
+{% block content %}
+    <h1>Page Not Found</h1>
+    <p>{{ error }}</p>
+{% endblock %}

File web/app/templates/410.html ADDED

  • Display 410: Deleted Page error within template base.html.
+{% extends "base.html" %}
+
+{% block title %}410: Deleted Page{% endblock %}
+
+{% block content %}
+    <h1>Deleted Page</h1>
+    <p>{{ error }}</p>
+{% endblock %}

File web/flaskapp.py MODIFIED

  • Create flash() success message for test route /hello_flaskapp.
  • Add @app.errorhandler(403) and render_template().
  • Add @app.errorhandler(404) and render_template().
  • Add @app.errorhandler(410) and render_template().
-from flask import render_template
+from flask import flash, render_template
+from markupsafe import Markup

...

 def hello_flaskapp():
     title = "Hello FlaskApp"
     logging.info("hello_flaskapp() : %s" % title)
+    flash(Markup("hello_flaskapp() : %s" % title), 'success')
     return render_template('hello.html', page_title=title)

...

+# Forbidden Page
+@app.errorhandler(403)
+def page_restricted(e):
+    return render_template('403.html', error=e), 403
+
+# Page Not Found
+@app.errorhandler(404)
+def page_not_found(e):
+    return render_template('404.html', error=e), 404
+
+# Deleted Page
+@app.errorhandler(410)
+def page_deleted(e):
+    return render_template('410.html', error=e), 410

Commit-v0.10 | Commit-v0.11 | Commit-v0.12

Clone this wiki locally