简单 ModelAdmin 示例的 TemplateDoesNotExist 错误

问题描述 投票:0回答:1

我在其他几个项目中使用了 Wagtail 的

ModelAdmin
,并取得了巨大成功,但这是我第一次尝试将它与继承自
Page
的模型一起使用。

我复制了简单示例模板并删除了与我的

BlogPageModel
无关的部分。

指向

ModelAdmin
的链接按预期显示,但当我单击它时,我得到
TemplateDoesNotExist at /admin/blog/blogpage/

我不记得之前必须设置模板。我缺少什么设置吗?

鹡鸰:1.9/ 姜戈:1.10.5 / Python:3.5.2

更新:我用继承自

models.Model
的模型进行了尝试,也得到了相同的结果。

回溯如下:

Internal Server Error: /admin/blog/blogpage/
Traceback (most recent call last):
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
    response = response.render()
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 109, in render
    self.content = self.rendered_content
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 84, in rendered_content
    template = self.resolve_template(self.template_name)
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 66, in resolve_template
    return select_template(template, using=self.using)
  File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/loader.py", line 53, in select_template
    raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: modeladmin/blog/blogpage/index.html, modeladmin/blog/index.html, modeladmin/index.html
[21/Feb/2017 07:56:38] "GET /admin/blog/blogpage/ HTTP/1.1" 500 110901
wagtail
1个回答
40
投票

我怀疑您错过了将

'wagtail.contrib.modeladmin'
添加到
INSTALLED_APPS

如果您使用的是 附加 wagtail-modeladmin 包(这是从 Wagtail 6.0 开始的唯一选项,因为它不再是 Wagtail 本身的一部分),添加到

INSTALLED_APPS
的路径是
'wagtail_modeladmin'

© www.soinside.com 2019 - 2024. All rights reserved.