Flask extension that applies common configurationsto all of webteam's flask apps.
Project description
Canonical Webteam Flask-Base
Flask extension that applies common configurations to all of webteam's flask apps.
Usage
from canonicalwebteam.flask_base.app import FlaskBase
app = FlaskBase(__name__, "app.name")
Or:
from canonicalwebteam.flask_base.app import FlaskBase
app = FlaskBase(
__name__,
"app.name",
template_404="404.html",
template_500="500.html",
favicon_url="/static/favicon.ico",
)
Features
Redirects and deleted paths
FlaskBase uses yaml-responses to allow easy configuration of redirects and return of deleted responses, by creating redirects.yaml
, permanent-redirects.yaml
and deleted.yaml
in the site root directory.
Error templates
FlaskBase
can optionally use templates to generate the 404
and 500
error responses:
app = FlaskBase(
__name__,
"app.name",
template_404="404.html",
template_500="500.html",
)
This will lead to e.g. http://localhost/non-existent-path
returning a 404
status with the contents of templates/404.html
.
Redirect /favicon.ico
FlaskBase
can optionally provide redirects for the commonly queried paths /favicon.ico
, /robots.txt
and /humans.txt
to sensible locations:
from canonicalwebteam.flask_base.app import FlaskBase
app = FlaskBase(
__name__,
"app.name",
template_404="404.html",
template_500="500.html",
favicon_url="/static/favicon.ico",
robots_url="/static/robots.txt",
humans_url="/static/humans.txt"
)
This will lead to e.g. http://localhost/favicon.ico
returning a 302
redirect to http://localhost/static/favicon.ico
.
Jinja2 helpers
You get two jinja2 helpers to use in your templates from flask-base:
now
is a function that outputs the current date in the passed format -{{ now('%Y') }}
->YYYY
versioned_static
is a function that fingerprints the passed asset -{{ versioned_static('asset.js') }}
->static/asset?v=asset-hash
robots.txt
and humans.txt
If you create a robots.txt
or humans.txt
in the root of your project, these will be served at /robots.txt
and /humans.txt
respectively.
Tests
To run the tests execute SECRET_KEY=fake python3 -m unittest discover tests
.
Project details
Release history Release notifications | RSS feed
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 canonicalwebteam.flask-base-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50901b1e8bc6bc098c57efa5cb0a9d8d143871bdf01cce8e3b8db18ff2f54021 |
|
MD5 | 05f6b08ec5c84ba1f0a09d2e5d819d3e |
|
BLAKE2b-256 | 62df476aa6a3066ce97a017379306592f89399b7bf3373876b52faf05b52c180 |
Hashes for canonicalwebteam.flask_base-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8126644c803c633a4cec5611b33c196120c1e3373ab1fd14b8a12799ded25cc0 |
|
MD5 | 0775d29d2fd9b119a76283df9166adf8 |
|
BLAKE2b-256 | da8e6e74fc67b72ed38441f4fac7bafd2674f5c843e294e93d64423dea23148d |