简体   繁体   English

在virtualenv中全新安装后,Django admin /template/文件夹丢失

[英]Django admin /template/ folder missing after fresh install in virtualenv

I get this error when trying to go to my Django app's admin panel:尝试转到我的 Django 应用程序的管理面板时出现此错误:

TemplateDoesNotExist at /admin/index.html TemplateDoesNotExist 位于 /admin/index.html

Exception Location: /home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py in find_template, line 139异常位置:/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) Template-loader postmortem Django 尝试按以下顺序加载这些模板: Using loader django.template.loaders.filesystem.Loader: Using 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 (文件不存在)

I have a new Django installation, haven't moved any files, and settings.py has django.contrib.admin added in INSTALLED_APPS .我有一个新的 Django 安装,没有移动任何文件,settings.py 在INSTALLED_APPS 中添加了django.contrib.admin

If I go to /.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/contrib/admin/ I do NOT find a /templates/ folder there (which would contained index.html and a bunch of other files).如果我转到/.virtualenvs/projectenv/local/lib/python2.7/site-packages/django/contrib/admin/我在那里找不到/templates/文件夹(其中包含 index.html 和一堆其他文件)。

However, exactly the same project, installed in a different machine DOES HAVE that /templates/ folder.但是,安装在不同机器上的完全相同的项目确实有/templates/文件夹。 I uninstalled and reinstalled Django in my virtual environment, but to no avail.我在我的虚拟环境中卸载并重新安装了 Django,但无济于事。

Installed apps in settings.py has the following: 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', )

And the full trace of the error I get is:我得到的错误的完整跟踪是:

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

Have you ever seen anything like it?你见过类似的东西吗? How do I solve this?我该如何解决这个问题?

I had to install an old django 1.3 with pip and I faced a similar problem.我不得不用pip安装一个旧的django 1.3 ,我遇到了类似的问题。 The templates folder was missing in the django app. django 应用程序中缺少templates文件夹。

Thanks to @manu comment on @shahz answer, I fixed the problem by reinstalling with感谢@manu 对@shahz 回答的评论,我通过重新安装解决了这个问题

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

A recent version of pip is required.需要最新版本的pip It may be updated with它可能会更新为

pip install --upgrade pip

I've seen this before.我以前见过这个。 /templates/ isn't the only folder you're probably missing. /templates/不是您可能丢失的唯一文件夹。 And note that you have a django folder placed here /yourvirtualenv/django/ that has all the required folders.请注意,您在/yourvirtualenv/django/中放置了一个 django 文件夹,其中包含所有必需的文件夹。 What will solve the problem for you is copying the files (without over-writing) from /yourvirtualenv/django/ to /yourvirtualenv/local/lib/python2.7/site-packages/django/ via the following ubuntu command: rsync -a -v --ignore-existing src dst where src is /yourvirtualenv/django/ (ie source) and dst is /yourvirtualenv/local/lib/python2.7/site-packages/django/ (ie destination).为您解决问题的是通过以下 ubuntu 命令将文件(不覆盖)从/yourvirtualenv/django/ /yourvirtualenv/local/lib/python2.7/site-packages/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/ (即目标)。 Next, just fire up Django admin again and it should work!接下来,再次启动 Django admin,它应该可以工作了!

I'm not exactly sure why this happens - anecdotally, it's pip misbehaving with legacy Django installations.我不确定为什么会发生这种情况 - 有趣的是,这是 pip 在旧 Django 安装中的行为不端。 I'll update this answer if I get new information on it.如果我获得有关它的新信息,我会更新此答案。 Good luck!祝你好运!

使用pip版本 20.2.4,它是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM