Python 在virtualenv中重新安装后,Django admin/template/文件夹丢失
尝试转到Django应用程序的管理面板时出现此错误: TemplateDoesNotExist位于/admin/index.html 例外情况 位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py 在find_模板中,第139行 模板加载程序postmortem Django尝试在中加载这些模板 此顺序:使用加载程序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在已安装的应用程序中添加了Python 在virtualenv中重新安装后,Django admin/template/文件夹丢失,python,django,templates,django-admin,Python,Django,Templates,Django Admin,尝试转到Django应用程序的管理面板时出现此错误: TemplateDoesNotExist位于/admin/index.html 例外情况 位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py 在find_模板中,第139行 模板加载程序postmortem Django尝试在中加载这些模板 此顺序:使用加载程序django.template.loade
Django.contrib.admin
如果我转到/.virtualenvs/projectenv/local/lib/python2.7/site packages/django/contrib/admin/
我在那里找不到/templates/
文件夹(其中包含index.html和一堆其他文件)
但是,安装在不同机器上的同一个项目确实有/templates/
文件夹。我在虚拟环境中卸载并重新安装了Django,但没有效果
settings.py中安装的应用程序具有以下功能:
已安装的应用程序=(
“django.contrib.auth”,
“django.contrib.contenttypes”,
#“django.contrib.sessions”,
“用户会话”,
“django.contrib.sites”,
“django.contrib.messages”,
“django.contrib.staticfiles”,
“django.contrib.admin”,
“django.contrib.comments”,
“myapp”,
“我的项目”,
“南方”,
“注册”,
“引导分页”,
“芹菜”,
“tweepy”,
“django.contrib.humanize”,
"分析",,
“mathfilters”,
#“请求”,
#“调试工具栏”,
#"分析",,
#“django_whosher”,
#取消注释下一行以启用管理文档:
#“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/不是您可能缺少的唯一文件夹。请注意,这里有一个django文件夹
/yourvirtualenv/django/
,其中包含所有必需的文件夹。解决问题的方法是通过以下ubuntu命令将文件从/yourvirtualenv/django/
复制到/yourvirtualenv/local/lib/python2.7/site packages/django/
:rsync-a-v——忽略现有的src-dst
,其中src
是/yourvirtualenv/django//code>(即源代码)和dst
是/yourvirtualenv/local/lib/python2.7/site packages/django/
(即目的地)。接下来,只需再次启动django admin,它就可以工作了
我不太清楚为什么会发生这种情况——有传闻说,这是pip在传统Django安装中的不当行为。如果我得到新的信息,我会更新这个答案。祝你好运!我不得不用pip
安装一个旧的Django 1.3
,我遇到了类似的问题。Django应用程序中缺少templates
文件夹
多亏了@manu对@shahz-answer的评论,我用重新安装修复了这个问题
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"
要解决此问题,您可以采用以下方法:最好使用'pip install--no binary django django'。是的,我可以确认,这是解决此问题的一种名副其实的方法!非常感谢!我花了一天时间调试它,认为是我的代码导致了此问题。