Navigation

If you want to use CouchDB (via the
couchdbkit package)
in Pyramid, you can use the following pattern to make your CouchDB database
available as a request attribute. This example uses the starter scaffold.
(This follows the same pattern as the MongoDB and Pyramid example.)

First add configuration values to your development.ini file, including your
CouchDB URI and a database name (the CouchDB database name, can be anything).

Configurator.add_request_method has been available since Pyramid 1.4.
You can use Configurator.set_request_property for Pyramid 1.3.

At this point, in view code, you can use request.db as the CouchDB database
connection. For example:

1
2
3
4
5
6
7
8
9
10

frompyramid.viewimportview_config@view_config(route_name='home',renderer='templates/mytemplate.pt')defmy_view(request):""" Get info for server """return{'project':'pyramid_couchdb_example','info':request.db.info()}

First let’s create a view for our page data in CouchDB. We will use the
ApplicationCreated event and make sure our view containing our page data.
For more information on views in CouchDB see
Introduction to CouchDB views.
In __init__.py: