Create Flask HTTP error handlers that use template rendering.
Project description
flask-error-templating
Create Flask HTTP error handlers that use template rendering. This is a very small and simple idea but I couldn't find anything like it so I made it myself.
Installation
Install with pip install flask-error-templating
Usage
create_http_error_handlers(app, error_pages, page_template_file)
app
is a handle to your Flask
object.
error_pages
is a list of ErrorPage
objects. It accepts three arguments: error_code
, message
and long_message
. error_code
and message
are required; long_message
is optional and if it is not present then it will not be rendered into the template.
page_template_file
is the filename of a HTML file in your projects templates
folder. Parameters supplied to the file for template rendering are error_code
, message
and long_message
. See the above paragraph for information on these parameters.
Complete basic example:
from flask import *
from flask_error_templating import ErrorPage, create_http_error_handlers
app = Flask(__name__)
@app.route('/')
def homepage():
return '<h1>Homepage</h1>'
error_pages = [
ErrorPage(400, 'Bad request'),
ErrorPage(400, 'Access is denied to this page.'),
ErrorPage(403, 'You are forbidden to view this page.'),
ErrorPage(404, 'The page you are looking for does not exist'),
ErrorPage(418, 'I\'m a teapot!')
]
create_http_error_handlers(app, error_pages, 'http_error.html')
if __name__ == '__main__':
app.run()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask-error-templating-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 829ab1111616184e8607a9e0afc75fdff264a4b8ff9c36873fea3cf2bc9d3a40 |
|
MD5 | 1f6eb0e26cf86b9ebdd9eff043bd9d8a |
|
BLAKE2b-256 | 9f44dbc205d007cedbb2b36a96e77bdb34238fb5a23cb35ef3e55d2cedb77736 |
Hashes for flask_error_templating-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6e8149f4c041848d1d6e25f0e7f28d24d416acdf8ff1aa756b35bce46d91d54 |
|
MD5 | 684a3dc2044972a6c929c54f2c7dbfa1 |
|
BLAKE2b-256 | 8d5f040b1e63f0e84af1966068866a0bb8f3540bc3209efc79e30dcd39a54cf4 |