class TemplateResponseMixin
from django.views.generic.base import TemplateResponseMixin
A mixin that can be used to render a template.
Descendants
- ArchiveIndexView
- CookieWizardView
- CreateView
- DateDetailView
- DayArchiveView
- DeleteView
- DetailView
- FormView
- ListView
- MonthArchiveView
- MultipleObjectTemplateResponseMixin
- NamedUrlCookieWizardView
- NamedUrlSessionWizardView
- NamedUrlWizardView
- SessionWizardView
- SingleObjectTemplateResponseMixin
- TemplateView
- TodayArchiveView
- UpdateView
- WeekArchiveView
- WizardView
- YearArchiveView
Attributes
Defined in | |
---|---|
response_class = <class 'django.template.response.TemplateResponse'>
|
TemplateResponseMixin |
template_name = None
|
TemplateResponseMixin |
Methods
def
get_template_names(self):
TemplateResponseMixin
¶
def
get_template_names(self):
TemplateResponseMixin
¶
Returns a list of template names to be used for the request. Must return a list. May not be called if render_to_response is overridden.
100 101 102 103 104 105 106 107 108 109 110 | def get_template_names(self):
"""
Returns a list of template names to be used for the request. Must return
a list. May not be called if render_to_response is overridden.
"""
if self.template_name is None:
raise ImproperlyConfigured(
"TemplateResponseMixin requires either a definition of "
"'template_name' or an implementation of 'get_template_names()'")
else:
return [self.template_name]
|
def
render_to_response(self, context, **response_kwargs):
TemplateResponseMixin
¶
def
render_to_response(self, context, **response_kwargs):
TemplateResponseMixin
¶
Returns a response with a template rendered with the given context.
89 90 91 92 93 94 95 96 97 98 | def render_to_response(self, context, **response_kwargs):
"""
Returns a response with a template rendered with the given context.
"""
return self.response_class(
request = self.request,
template = self.get_template_names(),
context = context,
**response_kwargs
)
|