【问题标题】:Django admin /template/ folder missing after fresh install in virtualenv在 virtualenv 中全新安装后,Django admin /template/ 文件夹丢失
【发布时间】: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

你见过类似的吗?我该如何解决?

【问题讨论】:

标签: python django templates django-admin


【解决方案1】:

pip 20.2.4 版本是:

pip install --no-binary :all: "django==1.3.7"

【讨论】:

    【解决方案2】:

    我必须用pip 安装旧的django 1.3,我遇到了类似的问题。 django 应用中缺少templates 文件夹。

    感谢@manu 对@shahz 答案的评论,我通过重新安装解决了这个问题

    pip install --no-binary django django==1.3.7
    

    需要最新版本的pip。可能会更新

    pip install --upgrade pip
    

    【讨论】:

    • 是的,这是名副其实的解决问题的方法,我可以确认!
    • 非常感谢!刚刚花了一天时间调试这个,以为是我的代码导致了这个问题。
    【解决方案3】:

    我以前见过这个。 /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 admin,它应该可以工作了!

    我不确定为什么会发生这种情况 - 有趣的是,它与旧版 Django 安装的 pip 行为不符。如果我得到关于它的新信息,我会更新这个答案。祝你好运!

    【讨论】:

    • 最好使用`pip install --no-binary django django"。
    猜你喜欢
    • 2021-11-23
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 2012-12-09
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多