What is the best location to put templates in django project?

后端 未结 9 669
情歌与酒
情歌与酒 2020-12-07 13:29

What is the best location to put templates in django project?

9条回答
  •  甜味超标
    2020-12-07 13:40

    Django 1.10

    TEMPLATE_DIRS is deprecated.

    Now we need to use TEMPLATE, introducing in Django 1.8 like this:

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [],
            'APP_DIRS': True,
            'OPTIONS': {
                # ... some options here ...
            },
        },
    ]
    

    Once you have defined TEMPLATES, you can safely remove ALLOWED_INCLUDE_ROOTS, TEMPLATE_CONTEXT_PROCESSORS, TEMPLATE_DEBUG, TEMPLATE_DIRS, TEMPLATE_LOADERS, and TEMPLATE_STRING_IF_INVALID.

    About the best location, Django looking for template like this :

    • DIRS defines a list of directories where the engine should look for template source files, in search order.
    • APP_DIRS tells whether the engine should look for templates inside installed applications. Each backend defines a conventional name for the subdirectory inside applications where its templates should be stored.

    More information : https://docs.djangoproject.com/en/1.10/topics/templates/#configuration

提交回复
热议问题