[英]Django rest framework connection with angular js services
我有一個其余的框架,序列化程序運行良好。 api.py文件將json顯示為以下格式。
網址:http://127.0.0.1:8000 / api / studentacademicprograms /
[
{
"credits_completed": 32,
"academic_program_gpa": 3.7,
"primary_program": true,
"academic_program": {
"acad_program_id": 124,
"acad_program_category": {
"id": 1,
"program_type": 1,
"title": "Associate in Arts"
},
"acad_program_type": {
"id": 2,
"program_type": "Certificate"
},
"acad_program_code": "AA.ARTS",
"program_title": "Associate in Arts Degree",
"required_credits": 60,
"min_gpa": 3.3,
"description": "another description"
}
}]
我還有一個angular js服務,當前正在從我手動創建的json文件中讀取靜態數據:
services.js:
angular.module('jsonService', ['ngResource'])
.factory('DegreesService', function($resource) {
return $resource('/static/json/degrees.json')
})
.factory('DegreeCategoriesService', function($resource) {
return $resource('/static/json/degreecategories.json')
})
.factory('DetailsService', function($resource) {
return $resource('/static/json/details.json')
})
.factory('ProgramsService', function($resource) {
return $resource('/static/json/programs.json')
});
但是現在我想更改角度工廠,使其從其余框架獲取json數據,而不是從靜態數據中讀取。 我該如何實現?
我建議為與您的API端點的交互提供服務-根據該服務的穩定性,考慮使用諸如restangular之類的東西,這會使事情變得更加容易。 如果您只需要一個只讀服務API,那么使用retangular會顯得過頭了。
在http://www.benlesh.com/2013/02/angularjs-creating-service-with-http.html上有關於如何執行此操作的很好的常規說明,在Convert Angular HTTP上有很好的相關stackoverflow問題.get功能到服務
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.