0

I want to move the templates folder up one level and out of the {{cookiecutter.project_slug}} folder.

I can use this and it works locally but I know it is not correct:

str ( ROOT_DIR + 'templates' )

what is the proper way to format this DIRS?

Here is what Django Cookiecutter uses:

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

cheers.

diogenes
  • 1,865
  • 3
  • 24
  • 51

2 Answers2

0

Not 100% certain, but it seems to work. Just added another os.path.dirname() to the DIR.

I created a BASE_DIR like a normal Django project then put it into the TEMPLATES.

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

cheers.

diogenes
  • 1,865
  • 3
  • 24
  • 51
0
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
        str(ROOT_DIR.path('templates'))
    ],
}

But why do you need to break the suggested structure?

sfdye
  • 296
  • 2
  • 5
  • just think it is a pain to have it buried down the extra level. I like to see the templates with all my apps. seems easier for me. I hope it is ok? thanks. – diogenes Nov 05 '17 at 03:28