A
A
Abdulla Mursalov2015-08-20 15:27:41
Ember.js
Abdulla Mursalov, 2015-08-20 15:27:41

How to make DRF and Ember.JS friends?

I want to know in detail how to work with this bundle.
1. How to output data to Ember from DRF? What steps need to be taken?
Registered router:

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
    this.route('products', { path: 'products' });
    this.route('product', {path: 'product/:product_id'});
});

export default Router;

... and the route itself:
import Ember from 'ember';

export default Ember.Route.extend({
  model: function () {
    return this.store.find('product');
  }
});

... described the model:
import DS from 'ember-data';

export default DS.Model.extend({
  scu: DS.attr(),
  full_title: DS.attr(),
  price: DS.attr()
});

... created an adapter:
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  host: 'http://127.0.0.1:8000',
  namespace: 'api'
});

Nothing works. Explain how to display the data from the example below? What are serializers for?
2. In what format should JSON be sent? For example api/products, it returns JSON like:
[
    {
        "id": 1,
        "scu": "191625",
        "title": "hp ProBook 450 G2",
        "price": "53598.00",
        "url": "http://127.0.0.1:8000/api/products/1/",
        "category": "Ноутбуки",
        "images": [
            {
                "id": 1,
                "image": "http://127.0.0.1:8000/media/catalog/product/images/191625/01.jpg"
            }
        ]
    },
   ...
]

However, this doesn't match the JSON API , I don't know how important it is yet, but the ember documentation says it should.
How to implement this in DRF?
3. I work with Ember using the Ember CLI. Ember is hosted on localhost:4200, Django on localhost:8000. When accessing the API, Ember gave an XMLHttpRequest cannot load error. Solved this with Django Cors Header by writing in settings.py
CORS_ORIGIN_ALLOW_ALL = True. As I understand it, there will be no such problem in the deployment? And what security issues does this entail?
4. How to avoid URL processing by Django?
Recommend what to read on this topic. If there is no summary guide, it will be possible to write a small tutorial based on this post.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexei, 2015-08-20
@amaprograma

I didn’t prepare such a bundle myself, but try to twist the project django-rest-framework-json-api project

S
Stanislav Romanov, 2015-08-20
@Kaer_Morchen

There was recently a question about the django rest framework, and working with the adapter. Look at the Ember.js tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question