简体   繁体   English

Django和Ember.js

[英]Django and Ember.js

Alright, so I'm trying to connect Django with ember.js using the django rest framework with the ember-data-django-rest-adapter . 好吧,所以我想使用django rest框架和ember-data-django-rest-adapter将Django与ember.js连接起来。 The application that I'm using to try this out is the todomvc example provided in the ember.js documentation. 我正在尝试使用的应用程序是ember.js文档中提供的todomvc示例

The ember application is currently hitting the server and getting a response (200) but nothing is loaded on the page. 该ember应用程序当前正在访问服务器并获得响应(200),但页面上未加载任何内容。

Here is the response from the django server: 这是来自django服务器的响应:

[02/Mar/2014 13:51:09] "GET /todos/?_=1393789869335 HTTP/1.1" 200 177

Here is the contents of that response from curl (note: this response is equivalent to a request for 'localhost/todos/'): 这是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
        }
    ]
}

The documentation for the adapter claims "The adapter assumes you have 2 different endpoints per django model." 适配器的文档要求“适配器假定每个django模型具有2个不同的端点。” The second is as follows and allows the request of an individual 'todo': 第二个如下,并允许个人“待办事项”的请求:

$> curl -H 'Accept: application/json; indent=4' http:/localhost:8080/todos/1/
{
    "title": "hmm why isnt this working now", 
    "isCompleted": false
}

I am thinking that the problem lies within my application.js: 我认为问题出在我的application.js中:

window.Todos = Ember.Application.create();

Todos.ApplicationAdapter = DS.DjangoRESTAdapter.extend({
  host: 'http://localhost:8080'
 });

 Todos.ApplicationSerializer = DS.DjangoRESTSerializer.extend();

If anyone has any ideas, any help would be greatly appreciated! 如果有人有任何想法,任何帮助将不胜感激! I can post more code if need be. 如果需要,我可以发布更多代码。 Thanks guys. 多谢你们。

EDIT: Debugging. 编辑:调试。 "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." “所请求的资源上没有'Access-Control-Allow-Origin'标头。因此,不允许访问源'null'。” Another thread led me to believe CORS might be able to solve this issue. 另一个线索使我相信CORS可能能够解决此问题。 I'll report back. 我会报告。

Don't use PaginationSerializer on the Django side. 不要在Django端使用PaginationSerializer DjangoRESTAdapter expects an array of items, not an object that describes the page. DjangoRESTAdapter需要一个项目数组,而不是描述页面的对象。 Relevant quote from ember-data-django-rest-adapter's readme : ember-data-django-rest-adapter的自述文件的相关引用:

iii) Pagination is not yet supported iii)尚不支持分页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM