如何扩展插件?

时间:2014-10-26 17:59:45

标签: python django python-2.7 django-cms

请帮助解决错误

在django cms中添加了插件民意调查。然后尝试为此tutorial扩展它。由于我的目录结构看起来like

问题是,当您尝试运行站点控制台时,会显示以下错误消息:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
    mw_instance = mw_class()
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/middleware/locale.py", line 24, in __init__
    for url_pattern in get_resolver(None).url_patterns:
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/home/kalinins/.virtualenvs/blogik4/blogik4/blogik4/urls.py", line 8, in <module>
    admin.autodiscover()
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
    import_module('%s.admin' % app)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/cms/admin/__init__.py", line 11, in <module>
    plugin_pool.plugin_pool.discover_plugins()
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/cms/plugin_pool.py", line 36, in discover_plugins
    load('cms_plugins')
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/cms/utils/django_load.py", line 56, in load
    get_module(app, modname, verbose, failfast)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/cms/utils/django_load.py", line 40, in get_module
    module = import_module(module_name)
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/home/kalinins/.virtualenvs/blogik4/blogik4/djangocms_polls/cms_plugins.py", line 17, in <module>
    plugin_pool.register_plugin(CMSPollPlugin)  # register the plugin
  File "/home/kalinins/.virtualenvs/blogik4/local/lib/python2.7/site-packages/cms/plugin_pool.py", line 87, in register_plugin
    % (plugin, template)
ImproperlyConfigured: CMS Plugins must define a render template (<class 'djangocms_polls.cms_plugins.CMSPollPlugin'>) that exists: djangocms_polls/poll_plugin.html

2 个答案:

答案 0 :(得分:0)

您需要在CMS_TEMPLATES变量中定义设置中的模板列表。

并且......将您现有的模板放到djangocms_polls子目录中,因此它将位于djangocms_polls/templates/djangocms_polls/poll_plugin.html

答案 1 :(得分:0)

您需要在模板文件夹中创建一个html模板

在这种情况下,您注册的模板文件夹poll_plugin.html

中的模板djangocms_polls
...
render_template = "djangocms_polls/poll_plugin.html"
..

此模板必须存在,以便CMS PLugin可以工作,这是插件呈现上下文数据的模板。