我在尝试转到Django应用程序的管理面板时遇到了这个错误:
TemplateDoesNotExist/admin/index.html
例外位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py在find_template中,第139行
模板加载器死后Django尝试加载这些模板,在此顺序:使用加载器django.template.loaders.filesystem.loader:使用加载程序django.template.loaders.app_directories.loader:/home/mhb11/folder/project/templates/admin/index.html(文件不存在)/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/bootstrap_pageation/templates/admin/index.html(文件不存在)
我安装了一个新的Django,没有移动任何文件,settings.py在INSTALLED_APPS中添加了django.contrib.admin
。
如果我转到/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/contrib/admin/
,我在那里找不到/templates/
文件夹(其中包含index.html和一堆其他文件)。
然而,完全相同的项目,安装在不同的机器上,确实有/templates/
文件夹。我在虚拟环境中卸载并重新安装了Django,但没有成功。
在设置中安装的应用程序。py具有以下功能:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.sessions',
'user_sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.comments',
'myapp',
'myproject',
'south',
'registration',
'bootstrap_pagination',
'djcelery',
'tweepy',
'django.contrib.humanize',
'analytical',
'mathfilters',
#'request',
#'debug_toolbar',
#'analytical',
#'django_whoshere',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
我得到的错误的完整轨迹是:
Internal Server Error: /admin/ Traceback (most recent call last): File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 140, in get_response
response = response.render() File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 105, in render
self.content = self.rendered_content File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 80, in rendered_content
template = self.resolve_template(self.template_name) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/response.py", line 58, in resolve_template
return loader.get_template(template) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/loader.py", line 146, in get_template
template, origin = find_template(template_name) File "/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/template/loader.py", line 139, in find_template
raise TemplateDoesNotExist(name) TemplateDoesNotExist: admin/index.html
你见过这样的东西吗?我该如何解决此问题?
我不得不用pip
安装一个旧的django 1.3
,我也遇到了类似的问题。django应用程序中缺少templates
文件夹。
感谢@manu对@shahz答案的评论,我通过重新安装解决了这个问题
pip install --no-binary django django==1.3.7
需要pip
的最新版本。可以使用进行更新
pip install --upgrade pip
我以前见过这种情况。/templates/
并不是您可能丢失的唯一文件夹。请注意,这里放置了一个django文件夹/yourvirtualenv/django/
,其中包含所有必需的文件夹。解决问题的方法是通过以下ubuntu命令将文件从/yourvirtualenv/django/
复制到/yourvirtualenv/local/lib/python2.7/site-packages/django/
(无需重写):rsync -a -v --ignore-existing src dst
,其中src
是/yourvirtualenv/django/
(即源),dst
是/yourvirtualenv/local/lib/python2.7/site-packages/django/
(即目的地)。接下来,只要再次启动Django管理员,它就可以工作了!
我不太清楚为什么会发生这种情况——有传言说,这是遗留Django安装的pip错误行为。如果我得到新的信息,我会更新这个答案。祝你好运!
对于pip
版本20.2.4,它是:
pip install --no-binary :all: "django==1.3.7"