2017-10-06 82 views
0

我想將模板文件夾向上移動一個級別並移出{{cookiecutter.project_slug}}文件夾。Django Cookiecutter將模板文件夾向上移動一個級別

我可以用這個和它的作品在本地,但我知道這是不正確的:

str (ROOT_DIR + 'templates') 

什麼是格式化這個DIRS的正確方法?

下面是Django的18.11用途:

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

歡呼。

回答

0

不是100%確定,但它似乎工作。剛剛添加了另一個os.path.dirname()到DIR。

我創建了一個BASE_DIR就像一個正常的Django項目,然後把它放入模板。

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')), 
    ], 
} 

歡呼聲。

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

但是,爲什麼你需要打破建議的結構?

+0

只是覺得讓它埋在額外的水平是件痛苦的事情。我喜歡用我所有的應用程序查看模板。對我來說似乎更容易。我希望它可以嗎?謝謝。 – diogenes

相關問題