所以我能够创建一个 HTML 设计文档 (CouchApp) 来查询视图,运行一些计算,然后将所有内容放入一个漂亮的 JSON 对象中并在浏览器/控制台中显示原始对象,但我想知道是否有办法让 HTML 文件的 GET 请求直接返回 JSON 对象?
我必须在一大组文档上运行多个视图,并且从 Django 单独调用每个视图需要很长时间。我的目标是能够将 httplib 输出到 HTML 页面,并将 JSON 对象返回到我的 Django 视图。
Sorry, there is not way to have it working the way you explained. Your CouchApp uses AJAX and does calculations using the javascript engine of the browser. Httplib will only get the html page for you, it won't evaluate the scripts.
What you probably need to is to have your data prepared in the list function instead of the couchapp. This is something you can easily invoke using httplib, its fed with the list of documents from the view and can return any http response.
Good luck!