开发者

Pymongo and Pyramid configure

I'm trying to configure me pyramid app like

https://github.com/niallo/pyramid_mongodb/blob/master/pyramid_mongodb/paster_templates/pyramid_mongodb/+package+/init.py_tmpl

but at config.registry.settings['mongodb_conn'] = conn get an error:

  File "/usr/local/lib/python2.6/dist-packages/pymongo-2.0.1-py2.6-linux-i686.egg/pymongo/database.py", line 682, in __call__
    "failing because no such method exists." % self.__name)
TypeError: 'Database' object is not callable. If you meant to call the '__html__' method on a 'Connection' object it is failing because no su开发者_开发问答ch method exists.

what's wrong?


This is actually a bug in pyramid_debugtoolbar <= 0.9. Upgrade to 0.9.1 or disable the debug toolbar.


if you're still interested about pymongo and pyramid, I'd recommend you using my pyramid_mongo package.

You can find it here:

http://pypi.python.org/pypi?:action=display&name=pyramid_mongo&version=0.1

And the documentation here:

http://packages.python.org/pyramid_mongo/

It's a bit more than just a scaffold. Unlike pyramid_mongodb, it tries to mimick the zodb package and probably some more cool things like traversal support. I never find a lot of time to do it. But it's coming out one day. At the moment, it's enough to use mongodb.


Check your MongoDB URI it should be in format like described here

http://www.mongodb.org/display/DOCS/Connections

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]


I'm currently using a workaround found here: https://groups.google.com/group/pylons-discuss/browse_thread/thread/394fb7ae9838f840/5d7a24a1d899844f?hl=fr&lnk=gst&q=html+mongodb+#5d7a24a1d899844f

In your __init__.py, just after the line

conn = pymongo.Connection(db_uri)

Add this:

conn.__html__ = lambda: "mongodb connection"

and this is enough to use the debug toolbar with mongodb as described in the pyramid cookbook.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜