简体   繁体   English

访问外部Web服务器Couchdb

[英]Access external web server couchdb

I search how access to an external web server thanks to couchdb but i don't find. 我搜索如何通过Couchdb访问外部Web服务器,但找不到。

My web application is stored on couchdb (localhost:5984) and my pictures (format png) are stores on the wev server (localhost:5986) runs with Python. 我的Web应用程序存储在couchdb(localhost:5984)上,我的图片(格式png)存储在使用Python运行的wev服务器(localhost:5986)上。

So, i want to get my pictures via my web application. 因此,我想通过Web应用程序获取图片。 Here is my configuration for couchdb in the file "local.ini": 这是我在文件“ 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 = *

once you access your db, you might want to consider building the url of each documents attachment as follows: 访问数据库后,您可能需要考虑如下构建每个文档附件的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   

and using Jinja2 templating: 并使用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