Search code examples
pythondjangopluginsdjango-cms

How do I put django cms plugins classes inside multiple files instead of just putting it all inside cms_plugins.py?


So I have a project where I am using Django CMS as the root of my project. First of all I'm new to Django CMS, and I now want to code some plugins to put into my pages. I searched for the solution but everywhere it says that I should put it inside cms_plugins.py.

I tried creating a folder named cms_plugins and created an __init__.py file inside it. Then I created the plugin inside a file named ThePlugin.py and coded my plugin the same way I did it in cms_plugins.py. Unfortunately it's not working. If someone can help me I'd be really gratefull. Thanks.


Solution

  • You're on the right track! cms_plugins is used to autodiscover plugins. Hence, you have to import the plugins from the __init__.py file, e.g.,

    from .ThePlugin import ThePlugin
    

    Alternatively, you can have a cms_plugin.py file and import them from wherever you'd like to have them:

    from my_plugin_collection.ux.general import ThePlugin