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 SECRET_KEY=fake 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.5.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: canonicalwebteam.flask_base-0.5.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.45.0 CPython/3.6.5

File hashes

Hashes for canonicalwebteam.flask_base-0.5.1.tar.gz
Algorithm Hash digest
SHA256 8b44503fb1404c4d6e082a374f253892c7c65697dacf92b4cf3b7eeeba0a4ecc
MD5 f976821934d08f0d5431750b6c2f5fe3
BLAKE2b-256 9f8238c0c4df32c7a588021541153798a90873be677d2db57e9fb16c7672d3c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canonicalwebteam.flask_base-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.45.0 CPython/3.6.5

File hashes

Hashes for canonicalwebteam.flask_base-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af8821c9757a46041b00ade9561289e26745faac059a00d3d4dc4e4b65783545
MD5 610f01497314fc8ff15a1e7823b01cb3
BLAKE2b-256 41ec09988f73e2df82cbc6a509c1833938d4c3591eddaa527d0dafcf9b53f7a0

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