Django-CMS 插件未出现

发布于 2024-11-25 11:46:32 字数 241 浏览 2 评论 0原文

我正在部署 Django 网站。我在计算机上运行的所有自定义插件(我可以从下拉列表中将它们添加到模板块中。)但是当我将代码推送到站点时,并非所有插件都可用。

数据库表已创建,如果我导入 plugin_pool 并调用 discover_plugins() 然后调用 get_all_plugins() 插件都会显示出来。所以我的问题是,为什么我的插件没有显示?有什么想法吗?

I'm deploying a Django website. All the custom plugins I have work on my computer (I can add them into a template block from the drop down.) but when I push the code out to the site, not all the plugins are available.

The database tables are created, and if I import plugin_pool and call discover_plugins() and then get_all_plugins() the plugins all show up. So my question is, why aren't my plugins showing? Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山有枢 2024-12-02 11:46:32

您的应用是否在 INSTALLED_APPS 中使用了插件(cms_plugins.py 文件)?

它是否有 models.py (可能为空)文件?

使用python manage.py shell时可以导入cms_plugins.py文件吗?

最常见的问题是 cms_plugins.py 文件中的导入错误

Is your app with the plugin (cms_plugins.py file) in INSTALLED_APPS?

Does it have a models.py (which could be empty) file?

Can you import the cms_plugins.py file when using python manage.py shell?

The most common problem are import errors in the cms_plugins.py file

○闲身 2024-12-02 11:46:32

我在遵循 Django CMS 3 的基本示例时遇到了此问题该示例表明以下代码将起作用(使用相关模板):

#cms_plugins.py
from cms.models.pluginmodel import CMSPlugin
class HelloPlugin(CMSPluginBase):
    model = CMSPlugin
    render_template = "hello_plugin.html"

plugin_pool.register_plugin(HelloPlugin)

但是,我发现当使用 CMSPlugin 作为模型时,插件在页面结构编辑器中不可见。

尽管插件位于以下位置:

  1. 在项目的 INSTALLED APPS 中列出的应用程序的根目录中
  2. 该应用程序有一个 models.py 文件(但插件未使用任何这些模型)
  3. 可以从 django shell 导入 cms_plugins.py 文件

尝试 django shell 导入,如示例页面中列出的:

$ python manage.py shell
>>> from django.utils.importlib import import_module 
>>> m = import_module("myapp.cms_plugins")

解决方案是使用定义在这models.py 文件,它扩展了 CMSPlugin:

#cms_plugins.py
from .models import MyModel

class HelloPlugin(CMSPluginBase):
    model = MyModel
    render_template = "hello_plugin.html"

plugin_pool.register_plugin(HelloPlugin)

# models.py
class MyModel(CMSPlugin):
    pass

就像魔术一样,该插件随后列在页面结构编辑器的“Generic”下。

I encountered this issue while following the basic example for Django CMS 3. The example suggests that the following code will work (with the associated template in place):

#cms_plugins.py
from cms.models.pluginmodel import CMSPlugin
class HelloPlugin(CMSPluginBase):
    model = CMSPlugin
    render_template = "hello_plugin.html"

plugin_pool.register_plugin(HelloPlugin)

However, I found that when using CMSPlugin as the model the plugin is not visible in the page structure editor.

This is despite the fact that the Plugin is:

  1. In the root directory of an app that is listed in the project's INSTALLED APPS
  2. The app had a models.py file (but the plugin was not using any of those models)
  3. The cms_plugins.py file could be imported from a django shell

Try the django shell import, as listed on the example page:

$ python manage.py shell
>>> from django.utils.importlib import import_module 
>>> m = import_module("myapp.cms_plugins")

The solution was to use a model defined in the models.py file, which extends CMSPlugin:

#cms_plugins.py
from .models import MyModel

class HelloPlugin(CMSPluginBase):
    model = MyModel
    render_template = "hello_plugin.html"

plugin_pool.register_plugin(HelloPlugin)

# models.py
class MyModel(CMSPlugin):
    pass

Like magic, the plugin was then listed under 'Generic' on the page structure editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文