-
Notifications
You must be signed in to change notification settings - Fork 8
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
- +9 -0 [M] web/app/main/templates/base.html
- +8 -0 [A] web/app/templates/403.html
- +8 -0 [A] web/app/templates/404.html
- +8 -0 [A] web/app/templates/410.html
- +19 -1 [M] web/flaskapp.py
- 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>
- 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 %}
- 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 %}
- 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 %}
- 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
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages