2013-10-17 237 views
0

也许我是用WordPress的思维模式来解决我的问题,但是我想实现的是Django项目的父/子主题的概念。我想我可以通过定义两个模板目录Django静态文件继承

TEMPLATE_DIRS = (
    '/home/Username/webapps/django/child/templates', 
    '/home/Username/webapps/django/parent/templates', 
) 

解决模板问题,但有没有办法用静态文件来实现这一目标?例如,我们向父级添加了一项新功能,更新了更新模板的父级应用程序,并添加了一些新的JavaScript,LESS和图像。

回答

0

您不需要指定两个模板目录。有一个父母和孩子模板的概念。所有子模板扩展父:

base.html文件(我们经常使用这个名字父)

<html> 
    <head> 
     <!-- Some css, js stuff goes here--> 
     {% block extra_head %} 
      <!-- A block where child templates add more css and js stuff if needed --> 
     {% endblock extra_head %} 
    </head> 
    <body> 
     {% block body %} 
      <!-- body content here --> 
     {% endblock body %} 
    </body> 
</html> 

然后子模板会延长base.html为:

child.html

{% extends "base.html" %} 

{% block body %} 
    <h1>Hello!</h1> 
{% endblock body %}