我有一个这样的项目结构mainproject
├── manage.py
├── mainproject
│ ├── settings.py
│ ├── templates
│ │ └── mainproject
│ │ └── index.html
│ ├── urls.py
│ ├── views.py
│ └── wsgi.py
└── app
├── admin.py
├── apps.py
├── forms.py
├── models.py
├── templates
│ └── app
│ ├── index.html
│ └── abc.html
├── urls.py
└── views.py
现在在我的设置.py我有TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['mainproject/templates', 'app/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',
],
},
},
]
当我在部署服务器的主域上使用它时(使用nginx和uwsgi部署),它工作得很好。你知道吗
我可以访问mainproject在domain.com的索引和app在domain.com/app的索引
但是当使用runserver时,只有domain.com:8000/app起作用,domain.com:8000给出错误TemplateDoesNotExist at /。你知道吗
为什么会这样?如何解决?你知道吗
模板加载程序验尸:Using engine django:
django.template.loaders.filesystem.Loader: /home/mohit/mainproject/templates/mainproject/index.html (Source does not exist)
django.template.loaders.filesystem.Loader: /home/mohit/app/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/Env/mainproject/lib/python2.7/site-packages/django/contrib/admin/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/Env/mainproject/lib/python2.7/site-packages/django/contrib/auth/templates/mainproject/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/mohit/mainproject/app/templates/mainproject/index.html (Source does not exist)
如果我在TEMPLATES中更改DIRS行设置.py并且成功了'DIRS': ['mainproject/mainproject/templates', 'app/templates'],
然后它在runserver上工作,而在部署服务器上不工作。你知道吗