我有一个 Django v1.3.1 站点在一个现在被破坏的服务器上(以前是在 Python v2.7.3 上)。我已经能够通过旧管理站点的缓存重建大部分内容,但是在新服务器实例 (Python v2.7.12) 上重新安装 Python 和 Django 后,我遇到了以下错误:
TemplateDoesNotExist at /admin/
admin/login.html
Request Method: GET
Django Version: 1.3.1
Exception Type: TemplateDoesNotExist
Exception Value:
admin/login.html
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/loader.py in find_template, line 138
Python Executable: /usr/bin/python
Python Version: 2.7.12
Python Path:
['/var/django/mysite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Server time: Sun, 15 Oct 2017 02:31:49 +0100
尝试加载模板的相关信息:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/var/django/mysite/templates/admin/login.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
在新机器上寻找/admin/index.html 我得到:
locate admin/login.html
/usr/local/django/contrib/admin/templates/admin/login.html
在旧机器上我得到:
locate admin/login.html
/root/build/Django/build/lib.linux-x86_64-2.7/django/contrib/admin/templates/admin/login.html
/root/build/Django/django/contrib/admin/templates/admin/login.html
/root/build/Django/tests/templates/custom_admin/login.html
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/admin/login.html
在启动和运行它的过程中我错过了什么/在开始升级到最新的 Django 版本之前我该如何解决这个问题?
编辑 - TEMPLATE_DIRS 的内容:
TEMPLATE_DIRS = ('/var/django/mysite/templates','C:/Users/jon/PycharmProjects/mysite/templates',)
我也有这个设置,所以我认为 app_dir 是 False 还是不是(?)并不重要:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
请您参考如下方法:
看起来我的 Django 安装已损坏(包括它的 pip 缓存)。整理如下:
rm -rf ~/.cache/pip
pip2.7 uninstall django
pip2.7 install django==1.3.1 --no-cache-dir
解决感谢答案here .
