我正在django项目中尝试使用unipath模块,这在Django的《两勺子》一书中已提到,但某些方法无法达到预期的效果。在我的settings.py中,我有以下内容:
from unipath import Path
BASE_DIR = Path(__file__).ancestor(2)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [(BASE_DIR.child('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',
],
},
},
]
STATIC_ROOT = BASE_DIR.child('static')
MEDIA_ROOT = BASE_DIR.child('media')
有了这些设置,我得到了TemplateDoesNotExist异常:
Using loader django.template.loaders.filesystem.Loader:
/var/www/(Path('/home/user/my_project/project/templates'),)/myapp/index.html (File does not exist)
我究竟做错了什么?
终于解决了这个问题!需要在settings.py中将TEMPLATES的'DIRS'字符串编辑为:
'DIRS': (BASE_DIR.child('templates'),),
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句