尝试访问我的Django应用程序的管理面板时出现此错误:
/admin/index.html上的TemplateDoesNotExist
异常 位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py 在find_template,第139行
模板加载器postmortem Django尝试加载这些模板 此顺序:使用loader django.template.loaders.filesystem.Loader: 使用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_pagination/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,但无济于事。
settings.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
你见过类似的东西吗?我该如何解决这个问题?
答案 0 :(得分:8)
我必须使用django 1.3
安装旧的pip
,我遇到了类似的问题。 django应用程序中缺少templates
文件夹。
感谢@manu对@shahz回答的评论,我通过重新安装
解决了这个问题pip install --no-binary django django==1.3.7
需要最新版本的pip
。它可能会用
pip install --upgrade pip
答案 1 :(得分:7)
我之前见过这个。 /templates/
不是您可能错过的唯一文件夹。请注意,您在此处放置了一个django文件夹/yourvirtualenv/django/
,其中包含所有必需的文件夹。为您解决问题的方法是通过以下ubuntu命令将文件(无需覆盖)从/yourvirtualenv/django/
复制到/yourvirtualenv/local/lib/python2.7/site-packages/django/
:rsync -a -v --ignore-existing src dst
其中src
为{{1} (即来源)和/yourvirtualenv/django/
是dst
(即目的地)。接下来,再次启动Django管理员,它应该可以工作!
我不确定为什么会这样 - 有趣的是,它与传统的Django安装行为不端。如果我获得有关它的新信息,我会更新这个答案。祝好运!
答案 2 :(得分:0)
对于pip
版本20.2.4,它是:
pip install --no-binary :all: "django==1.3.7"