【发布时间】:2015-03-21 23:02:52
【问题描述】:
我正在尝试使用 AngularJS + Restangular 与在 Django 中使用 Tastypie 创建的 API 进行交互。我已经以example code found here 为起点成功地与 API 进行了交互(如下所示)。
yourApp.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("/api");
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
if (operation === "getList") {
newResponse = response.objects;
newResponse.metadata = response.meta;
} else {
newResponse = response;
}
return newResponse;
});
RestangularProvider.setRequestSuffix('/?');
});
我想在我的 API 调用中使用 Tastypie 的过滤机制,但是这些参数是通过查询字符串而不是 URI 发送的。来自Tastypie docs 的示例:http://localhost:8000/api/v1/entry/?user__username=daniel
除了在每次请求之前重新配置 Restangular 的 setRequestSuffix 选项之外,还有什么干净的方法可以使用 Restangular 在查询字符串中应用 Tastypie 样式的过滤器吗?
【问题讨论】:
-
如果使用 POST 而不是 GET 会怎样?
标签: javascript django angularjs tastypie restangular