aldryn hello world issue

时间:2016-02-12 02:09:02

标签: python django django-cms divio

我自学了如何使用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的面孔。当我注释掉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)

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

1 个答案:

答案 0 :(得分: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'),