簡體   English   中英

訪問外部Web服務器Couchdb

[英]Access external web server couchdb

我搜索如何通過Couchdb訪問外部Web服務器,但找不到。

我的Web應用程序存儲在couchdb(localhost:5984)上,我的圖片(格式png)存儲在使用Python運行的wev服務器(localhost:5986)上。

因此,我想通過Web應用程序獲取圖片。 這是我在文件“ 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 = *

訪問數據庫后,您可能需要考慮如下構建每個文檔附件的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 %}`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM