Класс TemplateResponseMixin (Django 1.11)
from django.views.generic.base import TemplateResponseMixin
Миксин, который можно использовать для визуализации шаблона.
Диаграмма | Документация | Исходный код
Потомки
- ArchiveIndexView
- CreateView
- DateDetailView
- DayArchiveView
- DeleteView
- DetailView
- FormView
- ListView
- LoginView
- LogoutView
- MonthArchiveView
- MultipleObjectTemplateResponseMixin
- PasswordChangeDoneView
- PasswordChangeView
- PasswordResetCompleteView
- PasswordResetConfirmView
- PasswordResetDoneView
- PasswordResetView
- SingleObjectTemplateResponseMixin
- TemplateView
- TodayArchiveView
- UpdateView
- WeekArchiveView
- YearArchiveView
Атрибуты
Определено в | |
---|---|
content_type = None
|
TemplateResponseMixin |
response_class = <class 'django.template.response.TemplateResponse'>
|
TemplateResponseMixin |
template_engine = None
|
TemplateResponseMixin |
template_name = None
|
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.
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]
Возвращает ответ, используя для этого `response_class` с шаблоном, отображаемым в заданном контексте. Если предоставлены какие-либо ключевые аргументы, они будут переданы конструктору класса ответа.
def render_to_response(self, context, **response_kwargs):
"""
Returns a response, using the `response_class` for this
view, with a template rendered with the given context.
If any keyword arguments are provided, they will be
passed to the constructor of the response class.
"""
response_kwargs.setdefault('content_type', self.content_type)
return self.response_class(
request=self.request,
template=self.get_template_names(),
context=context,
using=self.template_engine,
**response_kwargs
)