我的问题是我必须对字典进行编码才能进行 couchdb 设计:
我有这个字典:
params = {'descending': 'true', 'startkey': 'Mexico', 'endkey': 'Mexico'}
我想要这样的网址:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=%22Mexico%22&endkey=%22Mexico%22
或像这样:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey="Mexico"&endkey="Mexico"
所以我urllib.urlencode
用来将dict转换为查询字符串:
urllib.urlencode(params)
这个返回给我类似的东西:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=Mexico&endkey=Mexico
所以这是 CouchDB 的无效 URL,因为 CouchDB 需要在startkey
和endkey
如果我将我的 dict 更改为:
params = {'descending': 'true', 'startkey': '"Mexico"', 'endkey': '"Mexico"'}
这个返回一个有效的 URL,如下所示:
http://localhost:5984/hello-world/_design/precios/_view/precios?descending=true&startkey=%22Mexico%22&endkey=%22Mexico%22
但是我不想在单引号内传递双引号,有没有办法可以返回一个有效的 URL?
感谢您的回答:D