python - Django 1.3.7 TemplateDoesNotExist 错误 admin/index.html

标签 python django ubuntu

此站点上有许多与此类似的问题,但我找不到可以解释这一特定行为的问题。

我对 django 和 ubuntu 比较陌生,所以解释可能很简单。这是我正在尝试迁移到新服务器的旧 (v1.3.7) django 项目。

这是我在我的 apache 日志中得到的完整错误:

TemplateDoesNotExist at /admin/
admin/login.html
Request Method: GET
Request URL:    http://131.212.123.7:26080/glrimon/admin/
Django Version: 1.3.7
Exception Type: TemplateDoesNotExist
Exception Value:    
admin/login.html
Exception Location: /.../leave_beave/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable:  /.../leave_beave/bin/python

leave_beave 是我的 virtualenv 的名称。

这是回溯传递的信息:

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/glri_mon/siteweb/templates/admin/login.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/glri_mon/siteweb/gps_upload/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/siteapp/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/glrimon_models/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/sdde/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/dv/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/contains/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/sqlwrite/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/tinymce/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/mptt/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/menus/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/plugins/text/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/plugins/picture/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/plugins/link/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/plugins/file/templates/admin/login.html (File does not exist)
/.../leave_beave/lib/python2.7/site-packages/cms/plugins/snippet/templates/admin/login.html (File does not exist)
/glri_mon/siteweb/cmsplugin_rst/templates/admin/login.html (File does not exist)

glri_mon 是django项目目录。 这是相关模板的路径:/.../leave_beave/django/contrib/admin/templates/admin/index.html。关于为什么 Django 没有在其搜索中包含该路径的任何想法?

这是来自 settings.py 的模板加载器:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

我在之前的一个问题中收到了同样的错误,我通过从有问题的模板目录创建一个符号链接(symbolic link)来解决它(.../python2.7/site-packages/lib.../package/templates) 到我的 /project_dir/templates 目录,这是在 settings.py 中配置为我的模板目录的目录:

TEMPLATE_DIRS = (
    os.path.join(PATH, 'templates'),
) 

当时我这样做了,因为我认为这是一种一次性的破解解决方案,但现在我在尝试访问我网站的管理页面 (http://.../admin/) 时遇到了同样的错误。这告诉我我要解决这个错误。

我想我可以向每个生成此错误的模板目录添加一个符号链接(symbolic link),但这对于生产站点来说似乎不是一个好主意。

我在这里错过了什么?

最佳答案

较新版本的 pip 将为包创建一个轮子,以便在您下次使用时加快安装速度。然而,正因为如此,模板被安装到虚拟环境根目录中。

1.4.22 添加了禁用 wheel 创建的解决方法 - https://github.com/django/django/commit/3b324970e390a6dc4c373db036d6f27300d7fded ,但是在此之前的任何操作都会创建 wheel 文件,从而导致诸如缺少模板之类的问题。

对 wheel 文件的官方支持已添加到 1.5.1 - https://github.com/django/django/commit/4391718f26466f82f943e37368181d5c0520fa35 .

使用 pip 版本 19,您可以使用 pip install --no-binary Django Django==1.3.7 跳过 wheel 安装/创建。旧版本的 pip 的命令行参数可能略有不同。

关于python - Django 1.3.7 TemplateDoesNotExist 错误 admin/index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40162788/

相关文章:

python - 如何通过迭代现有列的值来创建新列?

python - Pandas 系列基于索引的列的最大值

python - 如何编写从 zip 文件创建 InMemoryUploadedFile 的 python 测试?

ubuntu - 如何在ubuntu服务器上安装比特币钱包?

c++ - Qt qbs 项目设置与库未找到编译错误

java - 可区分的套接字输入

python - xticks 的旋转部分

python - Djangosyncdb 对 unicode 字符串的行为异常

jquery - 附加一个包含 jquery 的 django 模板

ubuntu - Pytest + GDAL : cannot allocate memory in static TLS block