访问外部Web服务器couchdb

时间:2014-05-14 14:04:10

标签: python couchdb

我搜索了如何通过couchdb访问外部Web服务器,但我找不到。

我的网络应用程序存储在couchdb(localhost:5984)上,我的图片(格式为png)是wev服务器上的存储(localhost:5986),用Python运行。

所以,我想通过我的网络应用程序获取我的照片。这是我在“local.ini”文件中对couchdb的配置:

[httpd_global_handlers]
_maps = { couch_httpd_proxy, handle_utils_dir_req, "<< localhost:5986 >> " }


[httpd]
enable_cors = true
allow_jsonp = true

[cors]
origins = *

1 个答案:

答案 0 :(得分:0)

访问数据库后,您可能需要考虑构建每个文档附件的URL,如下所示:

def function():

    couch = couchdb.Server()    #connect to server
    db = couch['img']         #connect to database which contains docs with img attachments
    doc_id = []                #create list of id's
    http_docid = []            #create list to populate href for picture path

    for i in db:                #for each id in the db
        doc_id.append(i)       #add to the carid list
        doc = db[i]             #get the document id
        for key in (doc['_attachments']):   #for the key in the doc '_attacments' payload
            print key #just to confirm
        href_docid.append(('http://yourdbDomain/dbname/'+i+'/'+key))  #create a uri and append to a list
    return href_docid   

并使用Jinja2模板:

{% for img in function() %}

  <img class="some-class" src="{{ img }}">

 {% endfor %}`