我正致力于创建一个"关于"我的网站的应用程序动态生成"关于"页面。对于应用程序的索引页面,我特别希望它显示"关于我们"页面中包含应用程序中的后续页面列表。
我正在努力弄清楚如何从查询集中访问该单个对象并通过TemplateView显示它?
以下是该视图的当前代码:
class AboutIndexView(TemplateView):
template_name = 'about/about.html'
def get_context_data(self, **kwargs):
context = super(AboutIndexView, self).get_context_data(**kwargs)
context['about_page'] = Page.objects.all().exclude(title='About Us')
context['about_us'] = Page.objects.filter(title='About Us')
return context
以下是模板的当前代码:
{% for page in about_us %}
<div class="text-center">
<h3>{{ page.title }}</h3>
</div>
{{ page.body|safe|linebreaks }}
{% endfor %}
重申一下这个问题,我将如何更改我的视图代码,以便我不再需要在模板代码中创建for循环,而只是能够显示&#34;关于我们&#34;直接?