在 virtualenv 中全新安装后 Django admin /template/ 文件夹丢失
Django admin /template/ folder missing after fresh install in virtualenv
我在尝试转到我的 Django 应用程序的管理面板时遇到此错误:
TemplateDoesNotExist at /admin/index.html
Exception
Location: /home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py
in find_template, line 139
Template-loader postmortem Django tried loading these templates, in
this order: Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/home/mhb11/folder/project/templates/admin/index.html (File does not
exist)
/home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/bootstrap_pagination/templates/admin/index.html
(File does not exist)
我安装了新的 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
你见过这样的东西吗?我该如何解决?
我以前见过这个。 /templates/
不是您可能缺少的唯一文件夹。请注意,您在此处 /yourvirtualenv/django/
放置了一个 django 文件夹,其中包含所有必需的文件夹。通过以下 ubuntu 命令将文件从 /yourvirtualenv/django/
复制(不覆盖)到 /yourvirtualenv/local/lib/python2.7/site-packages/django/
可以解决问题:rsync -a -v --ignore-existing src dst
where src
是 /yourvirtualenv/django/
(即源)并且 dst
是 /yourvirtualenv/local/lib/python2.7/site-packages/django/
(即目标)。接下来,再次启动 Django 管理,它应该可以工作了!
我不确定为什么会发生这种情况 - 有趣的是,它是旧版 Django 安装的 pip 行为不当。如果我获得有关它的新信息,我将更新此答案。祝你好运!
我不得不安装一个旧的 django 1.3
和 pip
,我遇到了类似的问题。 Django 应用程序中缺少 templates
文件夹。
感谢@manu 对@shahz 回答的评论,我通过
重新安装解决了这个问题
pip install --no-binary django django==1.3.7
需要 pip
的最新版本。它可能会更新为
pip install --upgrade pip
pip
版本 20.2.4 是:
pip install --no-binary :all: "django==1.3.7"
我在尝试转到我的 Django 应用程序的管理面板时遇到此错误:
TemplateDoesNotExist at /admin/index.html
Exception Location: /home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py in find_template, line 139
Template-loader postmortem Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: /home/mhb11/folder/project/templates/admin/index.html (File does not exist) /home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/bootstrap_pagination/templates/admin/index.html (File does not exist)
我安装了新的 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
你见过这样的东西吗?我该如何解决?
我以前见过这个。 /templates/
不是您可能缺少的唯一文件夹。请注意,您在此处 /yourvirtualenv/django/
放置了一个 django 文件夹,其中包含所有必需的文件夹。通过以下 ubuntu 命令将文件从 /yourvirtualenv/django/
复制(不覆盖)到 /yourvirtualenv/local/lib/python2.7/site-packages/django/
可以解决问题:rsync -a -v --ignore-existing src dst
where src
是 /yourvirtualenv/django/
(即源)并且 dst
是 /yourvirtualenv/local/lib/python2.7/site-packages/django/
(即目标)。接下来,再次启动 Django 管理,它应该可以工作了!
我不确定为什么会发生这种情况 - 有趣的是,它是旧版 Django 安装的 pip 行为不当。如果我获得有关它的新信息,我将更新此答案。祝你好运!
我不得不安装一个旧的 django 1.3
和 pip
,我遇到了类似的问题。 Django 应用程序中缺少 templates
文件夹。
感谢@manu 对@shahz 回答的评论,我通过
重新安装解决了这个问题pip install --no-binary django django==1.3.7
需要 pip
的最新版本。它可能会更新为
pip install --upgrade pip
pip
版本 20.2.4 是:
pip install --no-binary :all: "django==1.3.7"