javascript - Django 和 Ember.js

标签 javascript python django ember.js django-rest-framework

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

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” header 。因此不允许访问 Origin“null”。”另一个帖子让我相信 CORS 可能能够解决这个问题。我会回来报告的。

最佳答案

不要使用PaginationSerializer在 Django 这边。 DjangoRESTAdapter 需要一个项目数组,而不是描述页面的对象。相关引用来自 ember-data-django-rest-adapter 的 readme :

iii) Pagination is not yet supported

关于javascript - Django 和 Ember.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22133224/

相关文章:

javascript - 在javascript中递归搜索div

python - 有没有办法在断点处获取 python 调试 session 的 'snapshot'?

python - 创建 Stripe 订阅 Python

javascript - 将工具提示添加到 d3 散点图

javascript - 在浏览器中运行代码

JavaScript 监听器不断增加

python - django 在第一个脚本运行后每天将数据保存到文件中

python - 如何为 gedit 编写 python 命令?

python - ipython 或 jupyter 中的制表符补全会寻求什么来建议替代方案?

django - 将 Django 设置部署到生产环境的推荐方法是什么?