3

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

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

4

2 回答 2

4

您的应用程序是否带有插件(cms_plugins.py文件)INSTALLED_APPS

它有models.py(可能是空的)文件吗?

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

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

于 2011-08-08T13:13:56.047 回答
3

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.

于 2014-12-27T19:50:40.720 回答