好吧,所以我想使用Django REST框架和ember-data-django-rest-adapter将Django与ember.js连接起来。我正在尝试使用的应用程序是ember.js文档中提供的todomvc example

该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端使用PaginationSerializerDjangoRESTAdapter需要一个项目数组,而不是描述页面的对象。 ember-data-django-rest-adapter的readme的相关报价:


  iii)尚不支持分页

07-24 09:47
查看更多