开发者

Django-CMS plugin not appearing

开发者 https://www.devze.com 2023-03-22 07:26 出处:网络
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 plug

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 databas开发者_如何转开发e 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消