No project description provided
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.
Generating setup.py
In this project, for the time being, we maintain both a pyproject.toml
for Poetry and a setup.py
for traditional Python tooling. If you are developing on the module, you should update pyproject.toml
first and then regenerate the setup.py
using:
poetry install
poetry run poetry-setup
Tests
To run the tests execute poetry run python -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 Distributions
Hashes for canonicalwebteam.flask_base-0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2c92eb18db7356a72825c81f80ee6f11a1819f4ce200a16713d6c923425242b |
|
MD5 | 4ba370c61e6972510cab077a9311c282 |
|
BLAKE2b-256 | 86c9097287e249eaf5f04f20020c4b5e789b384f3aef5b9d294a2ac5cb039af8 |
Hashes for canonicalwebteam.flask_base-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad5ef39e50707442afff732fbc42462a5575f5bc4267c345f87abad98aed68d |
|
MD5 | a944ea001d7eb5aae99ff474f48cf430 |
|
BLAKE2b-256 | 90f6827790fd3ecb1a930b6a4925dc43f5d49185b800b67cacf0edd251bb4c3e |
Hashes for canonicalwebteam.flask_base-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cbc8efc80ae5498f08fa619f0e5c0e85e2df901909994db785dbba76d246f14 |
|
MD5 | c0d4e4e5dc6c7283fcfad2dc9e8164da |
|
BLAKE2b-256 | 50eb8e944a053fcce96fcfdcf9531b39e4c2e40ecb5f16012b8ff802b76a3367 |