【发布时间】:2014-04-03 16:50:50
【问题描述】:
好的,所以我正在尝试使用带有ember-data-django-rest-adapter 的 django rest 框架将 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 个不同的端点。”第二种如下,允许个人'todo'的请求:
$> 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 可能能够解决这个问题。我会回来报告的。
【问题讨论】:
标签: javascript python django ember.js django-rest-framework