【发布时间】:2015-05-28 06:56:10
【问题描述】:
我想要做的是向 django url 模式发送一个 $http GET 请求并返回一个 .json 文件。我可以使用 urlpatterns 来返回文件而不是视图吗?
这甚至可能吗?
当前表单/数据返回 500
testModule.js
angular.module('mod1', ['mod2'])
.controller('resorcesCtrl', ['mod2Factory',
function(mod2Factory) {
mod2Factory.getJSON();
}
]);
angular.module('mod2', [])
.factory('mod2Factory', [ '$http',
function($http) {
var getJSON = function() {
return $http({
url: "/form/data",
method: "GET"
})
}
return {
getJSON:getJSON
};
}
])
urls.py
url(r'^form/data', 'myApp.views.getJSON', name='getJSON'),
views.py
def getJSON(request):
context = {
"json": json
}
return render(request, '', context)
【问题讨论】:
-
您的 500 错误的内容是什么?你能把它和堆栈跟踪一起放在这里吗?哪个版本的 Django?
标签: javascript python json django angularjs