duck.routes.route_blueprint

Module for route arrangements using Blueprint. This acts as a set of routes, much like how Flask’s blueprints organize routes in a module.

Example:

app = Blueprint(location=__file__, name="products", urlpatterns=...)

Note

To resolve a url for a blueprint, the name should be {blueprint_name}.{path_name} .e.g., "api.followers" for blueprint named api and a path registered with name followers

Module Contents

Classes

Blueprint

Mini application for storing route information.

API

class duck.routes.route_blueprint.Blueprint(location: str, name: str, urlpatterns: Optional[List[duck.urls.URLPattern]] = None, prepend_name_to_urls: bool = True, static_dir: str = 'static', template_dir: str = 'templates', enable_static_dir: bool = True, enable_template_dir: bool = True, is_builtin: bool = False)[source]

Mini application for storing route information.

Initialization

Initialize the Blueprint.

Parameters:
  • location – The absolute path to where the blueprint is located.

  • name – A valid string representing the blueprint’s name.

  • urlpatterns – List of urlpatterns created using duck.urls.path or re_path.

  • prepend_name_to_urls – Whether to prepend name to urlpatterns. Defaults to True.

  • static_dir – The location of static files within the blueprint base directory.

  • template_dir – The template directory for the blueprint.

  • enable_static_dir – Boolean on whether to enable commands like duck collectstatic to access the blueprint staticfiles.

  • enable_template_dir – Expose the template dir for template resolving.

  • is_builtin – Flag the route blueprint as an internal builtin blueprint, Defaults to False (optional).

__names

[]

Names of all created blueprints.

__repr__()[source]
add_urlpattern(urlpattern: duck.urls.URLPattern)[source]

Adds a url pattern to the blueprint urlpatterns collection.

… admonition:: Notes

  • This reconfigures the urlpattern to belong to the blueprint before adding the url pattern.

property root_directory: str

Returns the absolute blueprint root path.

property root_directory_name: str

Returns the blueprint root path name.