[Django]-Django-CMS plugin not appearing

4👍

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

👤ojii

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.

Leave a comment