0

我想将模板文件夹上移一级并移出 {{cookiecutter.project_slug}} 文件夹。

我可以使用它并且它在本地工作,但我知道它不正确:

str ( ROOT_DIR + 'templates' )

格式化此 DIRS 的正确方法是什么?

这是 Django Cookiecutter 使用的:

ROOT_DIR = environ.Path ( __file__ ) - 3  
APPS_DIR = ROOT_DIR.path ( 'myapp' )

TEMPLATES = [
   {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        str(APPS_DIR.path('templates')),
    ],

    },
 },
]

https://github.com/pydanny/cookiecutter-django

干杯。

4

2 回答 2

0
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        str(ROOT_DIR.path('templates'))
    ],
}

但是为什么你需要打破建议的结构呢?

于 2017-11-04T03:23:43.577 回答
0

不是 100% 确定的,但它似乎有效。刚刚向 DIR 添加了另一个 os.path.dirname() 。

我像普通的 Django 项目一样创建了一个 BASE_DIR,然后将其放入模板中。

BASE_DIR = os.path.dirname ( os.path.dirname ( os.path.dirname ( os.path.abspath ( __file__ ) ) ) )


TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS'   : [
        str ( os.path.join ( BASE_DIR, 'templates' ) ),
    ],
}

干杯。

于 2017-10-11T01:42:56.713 回答