duck.routes

Module for route-specific actions.

Submodules

Package Contents

Functions

blueprint_joinpath

Joins directory to form a final blueprint resolvable path.

register_blueprints

Register some application blueprints.

register_urlpatterns

Register some application urlpatterns.

API

exception duck.routes.BlueprintJoinPathError(message, **kws)[source]

Bases: duck.exceptions.all.BlueprintError

Raised on function blueprint_joinpath if blueprint_subdir is not not really a subpath or doesn’t belong to blueprint root directory.

Initialization

Stores the error message in the message attribute.

Parameters:
  • message – The error message.

  • **kws – Additional keyword arguments.

exception duck.routes.BlueprintJoinPathNameNoMatch(message, **kws)[source]

Bases: duck.routes.BlueprintJoinPathError

Raised on function blueprint_joinpath If path’s root name is not equal to blueprint name. Handle this to avoid unnecessary lookup for unresolvable paths.

Initialization

Stores the error message in the message attribute.

Parameters:
  • message – The error message.

  • **kws – Additional keyword arguments.

duck.routes.blueprint_joinpath(blueprint_subdir: str, path: str, blueprint: duck.routes.route_blueprint.Blueprint) str[source]

Joins directory to form a final blueprint resolvable path.

This makes it easy to resolve sub blueprint paths/files.

Parameters:
  • blueprint_subdir – This is the absolute subdirectory to the blueprint root directory.

  • path – The path to join with, will be joined correctly without the path rootname if blueprint name == path rootname.

  • blueprint – The blueprint with the blueprint_subdir.

Raises:
  • ValueError – If path is not relative path.

  • BlueprintJoinPathError – If blueprint_subdir is not not really a subpath or doesn’t belong to blueprint root directory.

  • BlueprintJoinPathNameNoMatch – If path’s root name is not equal to blueprint name. Handle this to avoid unnecessary lookup for unresolvable paths.

Example:

# The blueprint_subdir can be any absolute blueprint subpath e.g. template_dir/static_dir
blueprint_subdir = "/some/absolute/blueprint/subpath"

# This is the target blueprint with the base_dir e.g. template dir
blueprint = SomeBlueprint(...)

# This is a path of a file you wanna resolve inside the blueprint_subdir
# For this to be resolvable in blueprint subdir, Blueprint name must be the first path part.
path = "blueprint_name/some/file"

# This works if the blueprint name == path root name even if the blueprint path is different.
print(blueprint_joinpath(base_dir, path, blueprint)) # Outputs: /some/absolute/blueprint/subpath/some/file
duck.routes.register_blueprints(blueprints: List[duck.routes.route_blueprint.Blueprint])[source]

Register some application blueprints.

duck.routes.register_urlpatterns(urlpatterns: List[duck.urls.URLPattern])[source]

Register some application urlpatterns.