发行Django&x27;s模板
事实上,我知道这在Django的模板中是不可能的,但我想执行发行Django&x27;s模板,django,listview,Django,Listview,事实上,我知道这在Django的模板中是不可能的,但我想执行{{Perception.objects.filter(loan\uuuu request\uuuu customer\uuu pk=207)} 以下是我用于该模板的视图: class PerceptionIndexView(StaffRestrictedMixin, FrontendListView): page_title = _('Perception') model = Perception templa
{{Perception.objects.filter(loan\uuuu request\uuuu customer\uuu pk=207)}
以下是我用于该模板的视图:
class PerceptionIndexView(StaffRestrictedMixin, FrontendListView):
page_title = _('Perception')
model = Perception
template_name = 'loanwolf/perception/index.html'
pjax_template_name = 'loanwolf/perception/index.pjax.html'
row_actions_template_name = 'loanwolf/perception/list-actions.inc.html'
url_namespace = 'perception'
def active(self, obj):
if obj.is_active:
return icon(obj.get_icon(), css_class='green-text', tooltip=_('Active'))
else:
return icon(obj.get_icon(), css_class='red-text', tooltip=_('Inactive'))
def notes_count(self, obj):
return obj.notes.count()
notes_count_label = _('Notes')
def get_change_url(self, obj):
return obj.get_absolute_url()
def my_view(self, A_pk):
filter_perceptions= Perception.objects.filter(loan__request__customer__pk=A_pk)
return render_to_response('../template/loanwolf/perception/list-view-#2.inc.html', {'filter_perceptions': filter_perceptions})
我尝试使用不同路径的render\u to\u response
,但到目前为止什么都没有发生。知道我的视图位于loanwolf/perception
中,我的模板列表视图-#2.inc.html
位于loanwolf/templates/loanwolf/perception
。此外,必须知道FrontendListView使用ListView。我想我不能使用“渲染到渲染响应”,但它不清楚
是否有人能提供其他解决方案,以便我可以访问模板中的列表Perception.objects.filter(loan\uu request\uu customer\uu pk)
提前谢谢 将
my\u视图中的代码放入名为get\u context\u data
的方法中,如下所示:
def get_context_data(self, **kwargs):
context = super(PerceiptionIndexView, self).get_context_data(**kwargs)
filter_perceptions = Perception.objects.filter(loan__request__customer__pk=...)
context["filter_perceptions"] = filter_perceptions
return context
然后,filter\u perceptions
将通过{{filter\u perceptions}}
在模板中可用
如果您需要一些稍微不同的东西,请查看文档中的更多示例。我很了解这种方法,但我不清楚如何做。问题:我可以使用{{customer.pk}
访问客户的pk。我可以用什么来代替你回答的…
?知道customer
是该模板上下文中的对象。您希望客户是什么?例如,如果是当前登录的用户,则可以使用self.request.user。您可以使用self.kwargs.Nice try访问其他参数,但我不能使用您的全部答案,因为self
是
是的,这就是self。它应该仍然包含这些变量。