在virtualenv中全新安装后缺少Django admin / template /文件夹 [英] Django admin /template/ folder missing after fresh install in virtualenv

查看:93
本文介绍了在virtualenv中全新安装后缺少Django admin / template /文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试转到Django应用的管理面板时出现此错误:

I get this error when trying to go to my Django app's admin panel:


TemplateDoesNotExist位于/​​admin/index.html

TemplateDoesNotExist at /admin/index.html

异常
位置:/home/mhb11/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/template/loader.py
在find_template中,第139行

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尝试以
的顺序加载这些模板:使用loader django.template.loaders.filesystem .Loader:
使用加载程序django.template.loaders.app_directories.Loader:
/home/mhb11/folder/project/templates/admin/index.html(文件不存在
) b $ b /home/mhb11/.virtualenvs/projectenv/local/lib/python2.7/site-packages/bootstrap_pagination/templates/admin/index.html
(文件不存在)

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具有 django.contrib.admin 添加到了 INSTALLED_APPS

I have a new Django installation, haven't moved any files, and settings.py has django.contrib.admin added in INSTALLED_APPS.

如果我去 /。virtualenvs / projectenv / local / lib / python2.7 / site-packages / django / contrib / admin / 我在那里没有找到 / templates / 文件夹(其中包含index.html和其他文件)。

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).

但是,安装在不同计算机上的完全相同的项目确实具有 / templates / 文件夹。我在虚拟环境中卸载并重新安装了Django,但无济于事。

However, exactly the same project, installed in a different machine DOES HAVE that /templates/ folder. I uninstalled and reinstalled Django in my virtual environment, but to no avail.

settings.py 中安装的应用具有以下内容:

Installed apps in settings.py has the following:

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',
#取消注释下一行以启用管理文档:
# '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?

推荐答案

我以前见过。 / templates / 不是您可能唯一丢失的文件夹。并注意,您在这里的django文件夹 / yourvirtualenv / django / 拥有所有必需的文件夹。将为您解决问题的是将文件(无覆盖)从 / yourvirtualenv / django / 复制到 / yourvirtualenv / local / lib / python2.7 / site-packages / django / 通过以下ubuntu命令: rsync -a -v --ignore-existing src dst 其中 src / yourvirtualenv / django / (即来源)和 dst /yourvirtualenv/local/lib/python2.7/site-packages/django / (即目标)。接下来,只需重新启动Django管理员,它便可以正常工作!

I've seen this before. /templates/ isn't the only folder you're probably missing. And note that you have a django folder placed here /yourvirtualenv/django/ that has all the required folders. 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 dstwhere src is /yourvirtualenv/django/ (i.e. source) and dst is /yourvirtualenv/local/lib/python2.7/site-packages/django/ (i.e. destination). Next, just fire up Django admin again and it should work!

我不确定为什么会发生这种情况-有趣的是,它与旧版Django的安装方式不符。如果有新的信息,我将更新此答案。祝好运!

I'm not exactly sure why this happens - anecdotally, it's pip misbehaving with legacy Django installations. I'll update this answer if I get new information on it. Good luck!

这篇关于在virtualenv中全新安装后缺少Django admin / template /文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆