简体   繁体   English

在Bluemix中,如何从带有集成Cloudant DB的Python Flask应用程序中检索Cloudant数据?

[英]In Bluemix, from a Python Flask App with integrated Cloudant DB, how do I retrieve Cloudant data?

I have a Python Flask app with integrated Cloudant running in Bluemix. 我有一个运行在Bluemix中的集成Cloudant的Python Flask应用程序。 The Cloudant database consists of a few documents. Cloudant数据库包含一些文档。 Each document has a "name" and an "email" field in addition to the default _id and rev field. 每个文档除了默认的_id和rev字段外,还具有一个“名称”和一个“电子邮件”字段。

Using the CouchDB interface I can easily print out the addresses of the db field 使用CouchDB接口,我可以轻松打印出db字段的地址

doc in db: docs +="<br>"+doc

gives the following result: 给出以下结果:

71076864699bfbd07b0f1684945e01ef _design/1e0c70cd2cad4211581be1c25adb1eea86d1b2f0 _design/3478963fd9207264b8ab48dbc23187ca9ad7204a 71076864699bfbd07b0f1684945e01ef _design / 1e0c70cd2cad4211581be1c25adb1eea86d1b2f0 _design / 3478963fd9207264b8ab48dbc23187ca9ad7204a

I now want to print out the actual values of the "name" and "email" fields. 我现在想打印出“名称”和“电子邮件”字段的实际值。 I can do that in the Cloudant UI with a Query or with an Index. 我可以在Cloudant UI中使用查询或索引来做到这一点。

How do I run this Query or Index from my Python app to show the actual values of the name and email fields? 如何从我的Python应用程序运行此查询或索引以显示名称和电子邮件字段的实际值? What is the best practice? 最佳做法是什么?

You'll need to make HTTP requests to the proper Cloudant endpoints using the credentials and URL for your Cloudant database that is provisioned for your application (found in the VCAP_SERVICES Environment Variable). 您需要使用为应用程序配置的Cloudant数据库的凭据和URL向正确的Cloudant端点发出HTTP请求(可在VCAP_SERVICES环境变量中找到)。

We have an alpha-stage python library , which we encourage you to use. 我们有一个alpha阶段的python库 ,建议您使用。 It can do basic things at the moment and reduces the amount of boilerplate code you will need. 目前,它可以做一些基本的事情,并减少所需的样板代码量。

This detailed Tutorial shows you how to do this. 这个详细的教程向您展示了如何执行此操作。

You can also find the Cloudant Python Documentation here 您还可以在此处找到Cloudant Python文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM