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
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:
- In the root directory of an app that is listed in the project’s
INSTALLED APPS
- The app had a
models.py
file (but the plugin was not using any of those models) - 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.
- [Django]-IntegrityError at /***/ (1048, "Column '***' cannot be null") in python django
- [Django]-How to get last login ip in django and save to a GenericIPAddressField?
- [Django]-How to add russian language support to Django CMS?
- [Django]-Uwsgi worker not distributing evenly
- [Django]-A better way to get only specific attributes from a Django queryset?