我正在学习 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
我正在尝试将路径添加到设置文件夹中的模板文件夹。但显示的错误
django.template.loaders.filesystem.Loader: .../muypicky/templates/index.html (源不存在)
当前设置.py 文件
TEMPLATES = [{
'DIRS': [os.path.join(BASE_DIR, 'templates')],
},]
查看错误,文件路径是错误的,因为它进入了 /muypicky/tempelates ,这是不正确的。那么我如何到达根文件夹,然后进入带有setting.py(base.py)中给定文件树的模板文件夹。
如有任何疑问,请随时询问,非常感谢。
解决方案:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
and
TEMPLATES = [{'DIRS': [
os.path.join(BASE_DIR, 'templates')
],},]
外加的os.path.dirname()
被包裹返回一个文件夹
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)