Skip to main content

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


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-1.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file canonicalwebteam.flask-base-1.0.1.tar.gz.

File metadata

  • Download URL: canonicalwebteam.flask-base-1.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for canonicalwebteam.flask-base-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fb923ec81c77fb23d33bcf77afc1e56ce7296c434f2cdebf9a7d923151971c63
MD5 72ea75919ca3d6861871fb0b92b7fb82
BLAKE2b-256 fdee67c2508c6debb690cbd798a0d13d426319e810c0524aacb5017d49230235

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicalwebteam.flask_base-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for canonicalwebteam.flask_base-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fbf879c64febf52a98a187a7ae3d76201ae708c7058bfc4041ca049653b0434a
MD5 4f201931aad696fa5a350bc2d24241e0
BLAKE2b-256 0bc7fd068e4ff0aeb80e3229b1e73be95fbc0fdc9fd16c5bb2e6a49aa02a3860

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