2014-05-14 320 views
0

我搜索如何訪問外部Web服務器感謝couchdb,但我沒有找到。訪問外部網絡服務器couchdb

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

所以,我想通過我的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 = * 
+0

請注意,標籤不是關鍵字。在你的問題中填寫完整的標籤列表(外部,網絡,服務器)將無法對它進行分類。 **請務必閱讀選擇標籤時出現的說明!** – Charles

+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 %}`