Django¶
Requires the django extra. See Django for
installation, configuration, and usage.
Client and shortcuts¶
- imgproxykit.integrations.django.get_client() Client[source]¶
Return the cached client configured by IMGPROXYKIT[‘client’].
Create the client on first use. Django’s
override_settingsclears the cache when entering and leaving an override ofIMGPROXYKIT.
-
imgproxykit.integrations.django.imgproxy_url(source: str | FieldFile, transform: Transform | str | None =
None) str[source]¶ Build an imgproxy URL using Django’s configured client.
- imgproxykit.integrations.django.imgproxy_variants[Key: str](source: str | FieldFile, variants: Mapping[Key, Transform]) dict[Key, str][source]¶
- imgproxykit.integrations.django.imgproxy_variants[Key: str](source: str | FieldFile, variants: str) dict[str, str]
Build named image URLs using Django’s configured client.
- Parameters:¶
- Returns:¶
URLs in variant order. Direct mappings preserve their key type.
- Raises:¶
KeyError – If a named variant set is not configured.
ValueError – If the default source resolver receives an empty file field.
Source resolution¶
- imgproxykit.integrations.django.sources.resolve_source(source: str | FieldFile) str[source]¶
Resolve an image source using Django’s configured resolver.
Call
source_resolverwith the original string or file field. The setting accepts a callable or a dotted import path to one. It must return a URI understood by the imgproxy server. This allows projects to resolve relative media URLs or construct storage URIs such ass3://bucket/keywithout accessing the field’s URL first.Without a resolver, return strings unchanged and use
FieldFile.urlfor file fields. Relative URLs are not expanded automatically.
- imgproxykit.integrations.django.sources.default_source_resolver(source: str | FieldFile) str[source]¶
Return a source string unchanged or use a file field’s storage URL.
Relative URLs are not expanded.
- Raises:¶
ValueError – If the file field has no associated file, as with direct access to
FieldFile.url.- Return type:¶
Settings¶
- class imgproxykit.integrations.django.SettingsDict[source]¶
Describe the IMGPROXYKIT dictionary for static type checking.
- client : Required[ClientSettingsDict]¶
Client constructor options; defaults remain in the core Client.
- source_resolver : Callable[[str | FieldFile], str] | str¶
Convert the original source to a URI, including empty file fields.
- class imgproxykit.integrations.django.ClientSettingsDict[source]¶
Describe client constructor options for static type checking.
- source_encoding : SourceEncoding¶
Source URL representation using Base64 or percent-encoded plain mode.