[英]Django and Ember.js
好吧,所以我想使用django rest框架和ember-data-django-rest-adapter將Django與ember.js連接起來。 我正在嘗試使用的應用程序是ember.js文檔中提供的todomvc示例 。
該ember應用程序當前正在訪問服務器並獲得響應(200),但頁面上未加載任何內容。
這是來自django服務器的響應:
[02/Mar/2014 13:51:09] "GET /todos/?_=1393789869335 HTTP/1.1" 200 177
這是curl響應的內容(注意:此響應等同於對“ localhost / todos /”的請求):
$> curl -H 'Accept: application/json; indent=4' http:/localhost:8080/todos/?_=1393789869335
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"title": "hmm why isnt this working now",
"isCompleted": false
},
{
"title": "interesttinnggggg",
"isCompleted": false
}
]
}
適配器的文檔要求“適配器假定每個django模型具有2個不同的端點。” 第二個如下,並允許個人“待辦事項”的請求:
$> curl -H 'Accept: application/json; indent=4' http:/localhost:8080/todos/1/
{
"title": "hmm why isnt this working now",
"isCompleted": false
}
我認為問題出在我的application.js中:
window.Todos = Ember.Application.create();
Todos.ApplicationAdapter = DS.DjangoRESTAdapter.extend({
host: 'http://localhost:8080'
});
Todos.ApplicationSerializer = DS.DjangoRESTSerializer.extend();
如果有人有任何想法,任何幫助將不勝感激! 如果需要,我可以發布更多代碼。 多謝你們。
編輯:調試。 “所請求的資源上沒有'Access-Control-Allow-Origin'標頭。因此,不允許訪問源'null'。” 另一個線索使我相信CORS可能能夠解決此問題。 我會報告。
不要在Django端使用PaginationSerializer
。 DjangoRESTAdapter
需要一個項目數組,而不是描述頁面的對象。 ember-data-django-rest-adapter的自述文件的相關引用:
iii)尚不支持分頁
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.