我要将templates文件夹上移一级并移出{{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
干杯。
发布于 2017-10-11 09:42:57
不是100%确定,但它似乎是有效的。刚刚向目录中添加了另一个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-11-04 11:23:44
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
str(ROOT_DIR.path('templates'))
],
}但是为什么你需要打破建议的结构呢?
https://stackoverflow.com/questions/46598758
复制相似问题