Mezzanine学习---使用自定义模板

Mezzanine是基于Django的CMS(内容管理系统),关于如何在Mezzanine的后台管理中创建的页面如何使用自定义的模板,而非Mezzanine自带的Page,RichTextPage模板。初学期间,Mezzanine在国内教程、资料甚少,故只得自己到外网下载英文官方文档学习。

The view function mezzanine.pages.views.page() handles returning a Page instance to a template. By default the template pages/page.html is used, but if a custom template exists it will be used instead. The check for a custom template will first check for a template with the same name as the Page instance’s slug, and if not then a template with a name derived from the subclass model’s name is checked for. So given the above example the templates pages/dr-seuss.html and pages/author.html would be checked for respectively. The view function further looks through the parent hierarchy of the Page. If a Page instance with slug authors/ dr-seuss is a child of the Page with slug authors, the templates pages/authors/dr-seuss.html, pages/authors/dr-seuss/author.html, pages/authors/author.html, pages/author.html, and pages/page.html would be checked for respectively. This lets you specify a template for all children of a Page and a different template for the Page itself. For example, if an additional author were added as a child page of authors/dr-seuss with the slug authors/dr-seuss/theo-lesieg, the template pages/authors/ dr-seuss/author.html would be among those checked。

 举例说明:比如我在models.py中定义了一个类名为MemberList继承page,在admin.py中注册后,在Mezzanine管理页面创建了一个member list页面,标题名为student。有如下几种方法:

1)        为MemberList类使用模板

                在工程文件夹(包含manage.py的目录)创建templates/pages文件夹,在pages文件夹下新建memberlist.html文件(注:就算model文件中class中声明为大写,此处也应为小写),即可为在mezzanine中创建的所有MemberList类的页面套用模板

2)        单独指定某一个页面的模板

                假设我在mezzanine中member下创建了一个页面(无关页面类型),在元数据中设置标题为student,url留空,生成网页的地址如下:

 那么要为这个页面使用自定义模板就在pages文件夹下新建member文件夹,在member文件夹下创建student.html文件,即可单独指定模板。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值