我正在部署一个 Django 网站。我在计算机上使用的所有自定义插件(我可以从下拉列表中将它们添加到模板块中。)但是当我将代码推送到站点时,并非所有插件都可用。
数据库表已创建,如果我导入plugin_pool
并调用discover_plugins()
,然后get_all_plugins()
插件都会显示出来。所以我的问题是,为什么我的插件没有显示?有任何想法吗?
我正在部署一个 Django 网站。我在计算机上使用的所有自定义插件(我可以从下拉列表中将它们添加到模板块中。)但是当我将代码推送到站点时,并非所有插件都可用。
数据库表已创建,如果我导入plugin_pool
并调用discover_plugins()
,然后get_all_plugins()
插件都会显示出来。所以我的问题是,为什么我的插件没有显示?有任何想法吗?
您的应用程序是否带有插件(cms_plugins.py
文件)INSTALLED_APPS
?
它有models.py
(可能是空的)文件吗?
使用时可以导入cms_plugins.py
文件python manage.py shell
吗?
最常见的问题是 cms_plugins.py 文件中的导入错误
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:
INSTALLED APPS
models.py
file (but the plugin was not using any of those models)cms_plugins.py
file could be imported from a django shellTry 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.