django 2.0中的模板路径出错
这是我的settings.py:django 2.0中的模板路径出错,django,python-3.x,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 forge
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',
],
},
},
]
这是我的错误:
使用引擎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
(源不存在)回溯开关t
我不明白这个网址:
/home/bussiere/Workspace/Bourse/Event/('templates',)/index.html (Source does not exist)
这是我的django版本:
->%django管理版本
2.0
你知道为什么吗
关于您已经获取了模板DIRS设置,它是一个元组,并将其包装在一个列表中,以将其添加到模板设置中。不要包装它:
'DIRS': TEMPLATE_DIRS,
更好的方法是,完全删除TEMPLATE_DIRS设置并直接内联定义:
'DIRS': ['templates'],
还要注意原始设置中的清晰方向:“不要忘记使用绝对路径”
您已经获取了模板\u DIRS设置,这是一个元组,并将其包装在一个列表中,以将其添加到模板设置中。不要包装它:
'DIRS': TEMPLATE_DIRS,
更好的方法是,完全删除TEMPLATE_DIRS设置并直接内联定义:
'DIRS': ['templates'],
还要注意原始设置中的清晰方向:“不要忘记使用绝对路径”