【问题标题】:aldryn hello world issue奥尔德林你好世界问题
【发布时间】:2016-05-23 01:46:12
【问题描述】:

我正在自学如何使用 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)

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

【问题讨论】:

  • 值得仔细检查一下,您的路径和对路径的引用确实都包含下划线,而不是破折号 (hello_world_ct)。
  • 要调试,您可以尝试通过 django 手动获取模板,看看这是模板加载的一般问题还是插件中的特定问题。先将cms_plugins.py中的plugin_pool.register_plugin(HelloWorld)注释掉,这样django就可以启动了。使用docker-compose run --rm web python manage.py shell 进入 django shell。然后from django.template import loader; loader.get_template("hello_world_ct/hello.html")。也可以尝试loader.get_template("base.html")(你知道的一些模板)作为测试参考。

标签: python django django-cms divio


【解决方案1】:

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

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'),

【讨论】:

    猜你喜欢
    • 2011-03-23
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2020-04-24
    • 2015-01-13
    相关资源
    最近更新 更多