我正在学习Django,并且正在学习Django 1.11教程。
这是我当前的项目树:
├── manage.py
├── muypicky
│ ├── __init__.py
│ ├── old_settings.py
│ ├── settings
│ │ ├── base.py # Contains the settings (like shown in the tutorial)
│ │ ├── __init__.py
│ ├── urls.py
│ └── wsgi.py
├── requirements.txt
├── restaurants
└── templates # Templates Folder
└── index.html
我正在尝试将路径添加到设置文件夹中的 tempelates 文件夹。但是显示的错误
django.template.loaders.filesystem.Loader: .../muypicky/tempelates/index.html (源不存在(
当前 setting.py 文件
TEMPLATES = [{
'DIRS': [os.path.join(BASE_DIR, 'tempelates')],
},]
查看错误,文件路径是错误的,因为它进入了不正确的/muypicky/tempelates 中。那么我如何访问根文件夹,然后在 setting.py (base.py( 中使用给定的文件树进入 tempelates 文件夹。
任何进一步的疑问,只是问和非常感谢期待。
我有相同的项目树,并在模板中放入:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'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.template.context_processors.media',
],
},
},
]
您可能拼错了名称,因为目录称为模板,但您的settings.py
正在寻找模板
├── manage.py
...
└── templates # Templates Folder
└── index.html
但是在您的设置中,您声明templates
TEMPLATES = [{
'DIRS': [os.path.join(BASE_DIR, 'templates')],
},]
这就是为什么贾尼奥找不到文件的原因
.../muypicky/templates/index.html (来源不存在(
错别字。将"模板"更改为"模板"。