1

我正在尝试为现有的 Pyramid 项目添加一个不错的管理界面。我使用创建了一个测试项目pcreate -s alchemy -s pyramid_fa fa_test,然后将创建的所有额外文件复制到我的项目中,并将它们更改为合适的。

在我尝试添加形式化路线之前,一切看起来都很好而且很漂亮:

config.formalchemy_model("/foo", package='bar',
                         model='bar.models.specific_models.Thingy',
                         **settings)

然后我得到:ImportError: No module named forms

我的问题是:我该如何解决这个问题?或者添加管理界面的正确方法是什么?

我用谷歌搜索了一堆无济于事...

以下是相关代码:

fainit.py:

from bar import models, faforms
import logging

def includeme(config):
    config.include('pyramid_formalchemy')
    config.include('bar.fainit')
    config.include('fa.jquery')
    config.include('pyramid_fanstatic')
    model_view = 'fa.jquery.pyramid.ModelView'
    session_factory = 'bar.models.access.DBSession'
    ## register session and model_view for later use
    settings = {'package': 'bar',
                'view': model_view,
                'session_factory': session_factory,
               }
    config.registry.settings['bar.fa_config'] = settings

    config.formalchemy_admin("/admin", models=models, forms=faforms,
                             **settings)

    # Adding the package specific routes
    config.include('shop.faroutes')
    log.info('formalchemy_admin registered at /admin')

faroutes.py

from bar import models
import logging
log = logging.getLogger(__name__)

def includeme(config):
    settings = config.registry.settings.get('shop.fa_settings}}', {})

    config.formalchemy_model("/alerts", package='shop',
                             model='shop.models.super_models.Alert',
                             **settings)

    log.info('shop.faroutes loaded')

和追溯:

Starting subprocess with file monitor
Traceback (most recent call last):
  File "../bin/pserve", line 9, in <module>
    load_entry_point('pyramid==1.5a1', 'console_scripts', 'pserve')()
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 51, in main
    return command.run()
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 316, in run
    global_conf=vars)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/scripts/pserve.py", line 340, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
    return context.create()
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/PasteDeploy-1.5.0-py2.7.egg/paste/deploy/util.py", line 56, in fix_call
    val = callable(*args, **kw)
  File "/home/sheena/WORK/tv_guys_env/shop/shop/__init__.py", line 30, in main
    includeme(config)
  File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 8, in includeme
    config.include('shop.fainit')
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
    c(configurator)
  File "/home/sheena/WORK/tv_guys_env/shop/shop/fainit.py", line 24, in includeme
    config.include('shop.faroutes')
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 778, in include
    c(configurator)
  File "/home/sheena/WORK/tv_guys_env/shop/shop/faroutes.py", line 12, in includeme
    **settings)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/util.py", line 507, in wrapper
    result = wrapped(self, *arg, **kw)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 58, in formalchemy_model
    view=view, models=[model], model=model, **kwargs)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid_formalchemy-0.4.4-py2.7.egg/pyramid_formalchemy/__init__.py", line 85, in formalchemy_admin
    forms = config.maybe_dotted('%s.forms' % package)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/config/__init__.py", line 848, in maybe_dotted
    return self.name_resolver.maybe_resolve(dotted)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 316, in maybe_resolve
    return self._resolve(dotted, package)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 323, in _resolve
    return self._zope_dottedname_style(dotted, package)
  File "/home/sheena/WORK/tv_guys_env/local/lib/python2.7/site-packages/pyramid-1.5a1-py2.7.egg/pyramid/path.py", line 372, in _zope_dottedname_style
    __import__(used)
ImportError: No module named forms
4

1 回答 1

0

听起来它正在寻找您在shop.faroutes.forms.

于 2013-09-27T15:25:01.037 回答