BaseRenderer
This class serves as an abstract base for template rendering, providing a consistent interface for generating HTML output for forms, formsets, and fields. It defines default template paths and a core render method while requiring subclasses to implement specific template loading logic via the get_template method.
Attributes
| Attribute | Type | Description |
|---|---|---|
| form_template_name | string = django/forms/div.html | The default path to the template used for rendering a form. |
| formset_template_name | string = django/forms/formsets/div.html | The default path to the template used for rendering a formset. |
| field_template_name | string = django/forms/field.html | The default path to the template used for rendering a single form field. |
| bound_field_class | class | The class used to represent a field that has been connected to a data source. |
Methods
get_template()
@classmethod
def get_template(
template_name: string
) - > [Template](../../template/base/template.md?sid=django_template_base_template)
Retrieves a template object by its name. Subclasses must implement this method to define how templates are loaded from the filesystem or other storage.
Parameters
| Name | Type | Description |
|---|---|---|
| template_name | string | The path or identifier of the template to be retrieved |
Returns
| Type | Description |
|---|---|
[Template](../../template/base/template.md?sid=django_template_base_template) | The template instance corresponding to the provided template name |
render()
@classmethod
def render(
template_name: string,
context: dict,
request: [HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest) = null
) - > string
Renders a template with a given context and optional request object. This method fetches the template via get_template and returns the resulting string with leading and trailing whitespace removed.
Parameters
| Name | Type | Description |
|---|---|---|
| template_name | string | The path or identifier of the template to render |
| context | dict | A dictionary of data used to populate the template variables |
| request | [HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest) = null | An optional HTTP request object used for context processors and CSRF token generation |
Returns
| Type | Description |
|---|---|
string | The rendered HTML content as a stripped string |