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文件,即可单独指定模板。