betty.url module

Provide a URL generation API.

final class betty.url.LocalizedPathUrlGenerator[source]

Bases: LocalizedUrlGenerator

Generate URLs for localizable file paths.

__init__(project: Project)[source]
generate(resource: Any, media_type: str, absolute: bool = False, locale: str | Locale | None = None) str[source]

Generate a URL for a resource.

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

class betty.url.LocalizedUrlGenerator[source]

Bases: _UrlGenerator

Generate URLs for localizable resources.

abstract generate(resource: Any, media_type: str, absolute: bool = False, locale: str | Locale | None = None) str[source]

Generate a URL for a resource.

final class betty.url.ProjectUrlGenerator[source]

Bases: LocalizedUrlGenerator

Generate URLs for all resources provided by a Betty project.

__init__(project: Project)[source]
generate(resource: Any, media_type: str, absolute: bool = False, locale: str | Locale | None = None) str[source]

Generate a URL for a resource.

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

final class betty.url.StaticPathUrlGenerator[source]

Bases: StaticUrlGenerator

Generate URLs for static (non-localized) file paths.

__init__(configuration: ProjectConfiguration)[source]
generate(resource: Any, absolute: bool = False) str[source]

Generate a URL for a resource.

supports(resource: Any) bool[source]

Whether the given resource is supported by this URL generator.

class betty.url.StaticUrlGenerator[source]

Bases: _UrlGenerator

Generate URLs for static (non-localizable) resources.

abstract generate(resource: Any, absolute: bool = False) str[source]

Generate a URL for a resource.