duck.routesยถ
Module for route-specific actions.
Submodulesยถ
Package Contentsยถ
Functionsยถ
Joins directory to form a final blueprint resolvable path. |
|
Register some application blueprints. |
|
Register some application urlpatterns. |
APIยถ
- exception duck.routes.BlueprintJoinPathError(message, **kws)[source]ยถ
Bases:
duck.exceptions.all.BlueprintErrorRaised on function
blueprint_joinpathif blueprint_subdir is not not really a subpath or doesnโt belong to blueprint root directory.Initialization
Stores the error message in the
messageattribute.- Parameters:
message โ The error message.
**kws โ Additional keyword arguments.
- exception duck.routes.BlueprintJoinPathNameNoMatch(message, **kws)[source]ยถ
Bases:
duck.routes.BlueprintJoinPathErrorRaised on function
blueprint_joinpathIf 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
messageattribute.- 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.