在jinja2模板中访问主页

在jinja2模板中访问主页

本文介绍了g,在jinja2模板中访问主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个页面扩展了base.html.主页和作品页面.我正在尝试将一个收藏夹图像添加到base.html.我决定将favicon字段添加到home_page,这是我的根页面.

I have two pages extending a base.html. home_page and works_page. I am trying to add a favicon image to the base.html. I have decided to add a favicon field to home_page which is my root page.

<link rel='icon' href='/media/{{page.favicon.file}}' />

当活动页面为works_page时,{{page}}没有网站图标字段,但出现错误.有没有一种方法可以始终从模板访问根页面?

When active page is works_page the {{page}} has no favicon field and I get an error. Is there a way to access always the root page from templates?

也许是{{root_page}}?

as {{ root_page }} maybe?

推荐答案

{{ request.site.root_page }}是获得它的一种方法.但是,我认为问题的根源是favicon不应是主页的字段,因为它通常是网站的属性,而不是该特定页面的属性. wagtail.contrib.settings模块将非常适合: http ://docs.wagtail.io/en/v1.13/reference/contrib/settings.html

{{ request.site.root_page }} is one way of obtaining it. However, I think the root of the problem is that favicon shouldn't be a field of the homepage, since it's a property of the site in general, not that specific page. The wagtail.contrib.settings module would be a good fit for this: http://docs.wagtail.io/en/v1.13/reference/contrib/settings.html

这篇关于g,在jinja2模板中访问主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:23