【发布时间】:2016-03-13 07:12:13
【问题描述】:
我在尝试访问 Django 应用的管理面板时收到此错误:
TemplateDoesNotExist 位于 /admin/index.html
例外 位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py 在 find_template 第 139 行
Template-loader postmortem 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_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
你见过类似的吗?我该如何解决?
【问题讨论】:
-
要解决这个问题,您可以按照以下方法:stackoverflow.com/a/34532454/5170753
标签: python django templates django-admin