django 2.0中的模板路径出错

use*_*794 0 django python-3.x

这是我的settings.py:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    #os.path.join(PROJECT_ROOT, 'templates').replace('\\','/'),
    "templates",
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIRS],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
Run Code Online (Sandbox Code Playgroud)

所以这是我的错误:

使用引擎django:

django.template.loaders.filesystem.Loader:/home/bussiere/Workspace/Bourse/Event/('templates',)/index.html(源不存在)django.template.loaders.app_directories.Loader:/ usr/local/lib/python3.5/dist-packages/django/contrib/admin/templates/index.html(源不存在)django.template.loaders.app_directories.Loader:/usr/local/lib/python3.5/ dist-packages/django/contrib/auth/templates/index.html(源不存在)Traceback Switch t

我不明白这个网址:

/home/bussiere/Workspace/Bourse/Event/('templates',)/index.html (Source does not exist) 
Run Code Online (Sandbox Code Playgroud)

这是我的django版本:

- >%django-admin版本2.0

如果你知道为什么

问候

Dan*_*man 5

您已经采用了TEMPLATE_DIRS设置,这是一个元组,并将其包装在一个列表中,以将其添加到您的TEMPLATES设置中.不要包装它:

    'DIRS': TEMPLATE_DIRS,
Run Code Online (Sandbox Code Playgroud)

更好的是,完全删除TEMPLATE_DIRS设置并直接内联定义:

    'DIRS': ['templates'],
Run Code Online (Sandbox Code Playgroud)

还要注意原始设置中的明确方向:"不要忘记使用绝对路径".

    'DIRS': [os.path.join(BASE_DIR, 'templates')],
Run Code Online (Sandbox Code Playgroud)