CKAN自定义主题错误

时间:2016-11-14 22:27:17

标签: ckan

我尝试按照this教程自定义CKAN模板,但我似乎无法运行开发服务器( paster serve /etc/ckan/default/development.ini ),因为错误'导入错误:没有名为插件的模块'。

这是plugin.py代码(位于 /usr/lib/ckan/default/src/ckanext-example_theme/ckanext/example_theme/plugin.py

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.common import config

def show_most_popular_groups():
    value = config.get('ckan.example_theme.show_most_popular_groups',False)
    value = toolkit.asbool(value)
    return value

def most_popular_groups():
    groups = toolkit.get_action('group_list')(data_dict={'sort' : 'package_count_desc', 'all_fields' : True})
    groups = groups[0:10]

    return groups

class Example_ThemePlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)
    plugins.implements(plugins.ITemplateHelpers)
    # IConfigurer

def update_config(self, config_):
    toolkit.add_template_directory(config_, 'templates')
    toolkit.add_public_directory(config_, 'public')
    toolkit.add_resource('fanstatic', 'example_theme')

def get_helpers(self):
    return {'example_theme_most_popular_groups' : most_popular_groups,
            'example_theme_show_most_popular_groups' : show_most_popular_groups}

setup.py源代码的一部分是这样的(位于 /usr/lib/ckan/default/src/ckanext-example_theme/setup.py

entry_points='''
    [ckan.plugins]
    example_theme=ckanext.example_theme.plugin:Example_ThemePlugin

    [babel.extractors]
    ckan = ckan.lib.extract:extract_ckan
''',

当我运行 python setup.py 开发时,它会成功运行。但是,当我运行 paster server /etc/ckan/default/development.ini 时会导致错误消息'导入错误:没有名为插件的模块'

我已将该插件包含在development.ini文件中(插件名称为example_theme)

ckan.plugins = stats text_view image_view recline_view pdf_view datastore datapusher **example_theme**

有人可以帮帮我吗?我哪里出错了?

任何帮助将不胜感激。感谢

修改 这是错误消息:

/usr/lib/ckan/default/local/lib/python2.7/site-packages/pylons/configuration.py:26: RuntimeWarning: Unable to load template engine entry point: 'pylonsmyghty = pylons.templating:MyghtyTemplatePlugin [myghty]': Traceback (most recent call last):
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pylons/templating.py", line 610, in <module>
Engine = entry_point.load()
File "/usr/lib/ckan/default/local/lib/python2.7/site-package/pkg_resources/__init__.py", line 2228, in load
self.require(*args, **kwargs)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2245, in require
items = working_set.resolve(reqs, env, installer)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 808, in resolve
if not req_extras.markers_pass(req):
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 993, in markers_pass
return not req.marker or any(extra_evals) or req.marker.evaluate()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 278, in evaluate
return _evaluate_markers(self._markers, current_environment)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 203, in _evaluate_markers
lhs_value = _get_env(environment, lhs.value)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/markers.py", line 185, in _get_env
"{0!r} does not exist in evaluation environment.".format(name)

UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.

import pylons.templating
Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 11, in <module>
sys.exit(run())
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 102, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 141, in invoke
exit_code = runner.run(args)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 236, in run
result = self.command()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/serve.py", line 284, in command
relative_to=base, global_conf=vars)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/serve.py", line 329, in loadapp
**kw)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
val = callable(*args, **kw)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/config/middleware/__init__.py", line 45, in make_app
load_environment(conf, app_conf)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/config/environment.py", line 97, in load_environment
p.load_all()
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 139, in load_all
load(*plugins)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 153, in load
service = _get_service(plugin)
File "/home/fajarmp/ckan/lib/default/src/ckan/ckan/plugins/core.py", line 255, in _get_service
return plugin.load()(name=plugin_name)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named plugin

1 个答案:

答案 0 :(得分:0)

尝试使用这些插件设置:

ckan.plugins = stats text_view recline_view example_theme
ckan.plugins = stats text_view image_view recline_view  

按顺序放置它们应该有效。 我注意到我之前已经互换了。