duck.contrib.responses.base

Duck Framework built-in response factory.

Transforms bare HttpResponse subclasses into fully rendered, themed HTML responses using Duck’s internal template engine.

Module Contents

Functions

async_make_response

Async variant of make_response for use inside async views and handlers.

make_response

Transforms an HttpResponse subclass into a themed HTML response.

Data

DEFAULT_FAVICON

API

duck.contrib.responses.base.DEFAULT_FAVICON

None

async duck.contrib.responses.base.async_make_response(response_class: Type[duck.http.response.HttpResponse], title: str = None, heading: str = None, body: str = None, status_code: int = None, status_label: str = None, icon_link: str = DEFAULT_FAVICON, icon_type: str = 'image/png', debug: bool = None, extra_context: Optional[Dict[Any, Any]] = None, template: Optional[str] = None) duck.http.response.TemplateResponse[source]

Async variant of make_response for use inside async views and handlers.

Transforms an HttpResponse subclass into a themed HTML response using Duck’s async internal template renderer. Behaviour is identical to make_response except the render step is awaited.

Parameters:
  • response_class – A subclass of HttpResponse to render.

  • title – Browser tab title. Defaults to the response status message.

  • heading – Primary heading shown on the page. Defaults to the response status message.

  • body – Body text or HTML. Defaults to the response status explanation.

  • status_code – HTTP status code passed to the template watermark. Inferred from the response class when omitted.

  • status_label – Human-readable status label e.g. “Not Found”. Inferred when omitted.

  • icon_link – URL to the favicon. Defaults to Duck’s built-in favicon.

  • icon_type – MIME type of the favicon. Required when icon_link is provided.

  • debug – Renders the debug notice when True. Defaults to the DEBUG setting.

  • context – The extra context to pass to the base template.

  • template – The internal template to use, defaults to base.html.

Returns:

A TemplateResponse with the rendered HTML body and correct status code.

Raises:
  • TypeError – If response_class is not a subclass of HttpResponse.

  • TypeError – If icon_link is provided without icon_type.

duck.contrib.responses.base.make_response(response_class: Type[duck.http.response.HttpResponse], title: str = None, heading: str = None, body: str = None, status_code: int = None, status_label: str = None, icon_link: str = DEFAULT_FAVICON, icon_type: str = 'image/png', debug: bool = None, extra_context: Optional[Dict[Any, Any]] = None, template: Optional[str] = None) duck.http.response.TemplateResponse[source]

Transforms an HttpResponse subclass into a themed HTML response.

Uses Duck’s internal base template to produce a styled error or informational page. Falls back to the response class’s own status message and explanation when title, heading, or body are omitted.

Parameters:
  • response_class – A subclass of HttpResponse to render.

  • title – Browser tab title. Defaults to the response status message.

  • heading – Primary heading shown on the page. Defaults to the response status message.

  • body – Body text or HTML. Defaults to the response status explanation.

  • status_code – HTTP status code passed to the template watermark. Inferred from the response class when omitted.

  • status_label – Human-readable status label e.g. “Not Found”. Inferred when omitted.

  • icon_link – URL to the favicon. Defaults to Duck’s built-in favicon.

  • icon_type – MIME type of the favicon. Required when icon_link is provided.

  • debug – Renders the debug notice when True. Defaults to the DEBUG setting.

  • extra_context – The extra context to pass to the base template.

  • template – The internal template to use, defaults to base.html.

Returns:

A TemplateResponse with the rendered HTML body and correct status code.

Raises:
  • TypeError – If response_class is not a subclass of HttpResponse.

  • TypeError – If icon_link is provided without icon_type.