Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canonicalwebteam.flask_base-0.4.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file canonicalwebteam.flask_base-0.4.3.tar.gz.

File metadata

File hashes

Hashes for canonicalwebteam.flask_base-0.4.3.tar.gz
Algorithm Hash digest
SHA256 99d232705ad78eb9dfa9c7a0df57576dc58bb82b3f58492eba8152a0eb4470fc
MD5 645a6b4afbb1fc12a18d9228103ea226
BLAKE2b-256 af0de9a4206b3b73dc8a35f29098759ef4203f5e87557668ff2e40cba5591813

See more details on using hashes here.

File details

Details for the file canonicalwebteam.flask_base-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for canonicalwebteam.flask_base-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 90a5c8eb46f5468340a91e90469dd8773ba184bfcf2666c85d8430be4f13318b
MD5 dd8bfd33324f43145ef63aff68b55019
BLAKE2b-256 607916079be5740d7a7923d78b8973b8d524c6ef539cbef0b43035e216b2c4ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page