class django.views.generic.base.TemplateResponseMixin
Provides a mechanism to construct a TemplateResponse
, given suitable context. The template to use is configurable and can be further customized by subclasses.
Attributes
-
template_name
-
The full name of a template to use as defined by a string. Not defining a
template_name
will raise adjango.core.exceptions.ImproperlyConfigured
exception.
-
template_engine
-
The
NAME
of a template engine to use for loading the template.template_engine
is passed as theusing
keyword argument toresponse_class
. Default isNone
, which tells Django to search for the template in all configured engines.
-
response_class
-
The response class to be returned by
render_to_response
method. Default isTemplateResponse
. The template and context ofTemplateResponse
instances can be altered later (e.g. in template response middleware).If you need custom template loading or custom context object instantiation, create a
TemplateResponse
subclass and assign it toresponse_class
.
-
content_type
-
The content type to use for the response.
content_type
is passed as a keyword argument toresponse_class
. Default isNone
– meaning that Django usesDEFAULT_CONTENT_TYPE
.
Methods
-
render_to_response(context, **response_kwargs)
-
Returns a
self.response_class
instance.If any keyword arguments are provided, they will be passed to the constructor of the response class.
Calls
get_template_names()
to obtain the list of template names that will be searched looking for an existent template.
-
get_template_names()
-
Returns a list of template names to search for when rendering the template. The first template that is found will be used.
If
template_name
is specified, the default implementation will return a list containingtemplate_name
(if it is specified).
Please login to continue.