3

我正在自学如何使用 Aldryn 来托管 django-cms 网站。我一直在阅读readthedocs网站上的应用程序开发教程,并且几乎一直到最后。当我运行时,aldryn project up我收到一个错误,告诉我检查日志。我使用检查日志docker-compose logs web,在日志末尾我看到:django.core.exceptions.ImproperlyConfigured: CMS Plugins must define a render template (<class 'hello_world_ct.cms_plugins.HelloWorld'>) that exists: hello_world_ct/hello.html

出于某种原因,aldryn 项目似乎无法识别我在class HelloWorld(CMSPluginBase):. 当我注释掉 render_template 时,日志给了我同样的错误。

我已经按照教程告诉我的方式设置了项目。addons-dev 文件夹内的目录树是这样的:

hello-world-ct/
├── addon.json
├── hello_world_ct
│   ├── admin.py
│   ├── cms_plugins.py
│   ├── cms_plugins.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── models.pyc
│   ├── templates
│   │   └── hello_world_ct
│   │       └── hello.html
│   ├── tests.py
│   └── views.py
├── LICENSE
├── MANIFEST.in
├── README.rst
└── setup.py

cms_plugins.py 文件如下所示:

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.models.pluginmodel import CMSPlugin

class HelloWorld(CMSPluginBase):
    model = CMSPlugin
    render_template = "hello_world_ct/hello.html"
    text_enabled = True

plugin_pool.register_plugin(HelloWorld)

...它看起来对我来说,但也许我错过了一些东西。

4

1 回答 1

0

我有同样的问题。这是对我有用的解决方案。

settings.py文件中,将应用的模板文件夹添加到TEMPLATES变量中:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'your_core_app', 'core_app_templates_folder'),
            os.path.join(BASE_DIR, 'hello_world_ct', 'templates'),
        ],
        'OPTIONS': {
             ...
        },
    },
]

并将模板名称添加到CMS_TEMPLATES变量中:

CMS_TEMPLATES = (
    ('fullwidth.html', 'Fullwidth'),
    ...
    ('hello.html', 'Hello World CT'),

于 2020-12-20T13:19:25.947 回答