【问题标题】:Access external web server couchdb访问外部 Web 服务器 couchdb
【发布时间】:2016-05-10 14:56:03
【问题描述】:

感谢 couchdb,我搜索了如何访问外部 Web 服务器,但我没有找到。

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

所以,我想通过我的网络应用程序获取我的照片。这是我在文件“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 = *

【问题讨论】:

  • 请注意标签不是关键字。在标签列表中塞满与您的问题(外部、网络、服务器)相同的单词将无助于对其进行分类。 请务必阅读选择标签时出现的说明!
  • 好的,感谢您的修改。

标签: python couchdb


【解决方案1】:

访问数据库后,您可能需要考虑构建每个文档附件的 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 %}`

【讨论】:

    猜你喜欢
    • 2020-02-28
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    相关资源
    最近更新 更多