2015-10-13 76 views
4

我看到有两种方法可以在项目中构建模板。模板可以存储在蓝图的templates/文件夹中,或者每个蓝图在全局模板文件夹内都有一个文件夹。两者有什么区别?为什么我应该使用一个呢?模板应该位于蓝图模板文件夹还是全局模板文件夹中?

app/ 
    blueprint1/ 
     __init__.py 
     views.py 
     templates/ 
    blueprint2/ 
     __init__.py 
     views.py 
     templates/ 
    templates/ # Global templates folder 
app/ 
    blueprint1/ 
     __init__.py 
     views.py 
    blueprint2/ 
     __init__.py 
     views.py 
    templates/ # Global templates folder 
     blueprint1/ 
     blueprint2/ 
+1

就我个人而言,我会选择2,因为一切都在一个地方。 – karthikr

+0

我使用第一个,特别是当蓝图用于提供完全不同的有力。 –

回答

4

两者在合剂看到什么条件等同,其神社装载机结合的蓝图和全球性的文件夹。蓝图模板被视为默认源,并且全局源覆盖这些模板。通常情况下,蓝图模板仅在您编写其他人将安装并覆盖的扩展名时才有用,如果您只是在内部使用它,则不提供任何内容。请注意,您需要在蓝图和全局文件夹中使用相同的文件夹结构,否则您将看到意外冲突,因为加载器直接覆盖文件夹,而不是蓝图名称。

project/ 
    package/ 
     __init__.py 
     blueprint1/ 
      __init__.py 
      templates/ 
       blueprint1/ 
        page.html # default 
     templates/ 
      blueprint1/ 
       page.html # overrides blueprint