Division of responsibilities between Django and Ember


#1

Hi All,

I have been trying out Ember with a Django backend and am very excited about it. I was learning through django-ember-grunt which @toranb generously helped me with, in a previous post .

I was building upon his sample app and recently have come across some decision problems regarding Django and Ember. Specifically, the following questions:

  1. For a real time application, (e.g. Disqus) will it be a good idea to just use Django as a REST API backend, with Ember handling all the client side presentation and routing?

  2. All of the Django third party apps which I want to use are pretty much made to leverage the complete Django setup (routing, views, templates). If I want to use Ember templates only, then is it advisable to use these third party apps?

  3. The thing which looks helpful in these apps is the models. However, these models are accompanied by other constructs like helper functions, which are supposed to be used by Django views. How can I utilize these third party apps from Ember (will save me a lot of effort and time) without writing too much of code on the backend? Is there a good approach for doing this using Ember.js mostly?

  4. A REST API exposed through Django will allow me to do CRUD on the database through Ember. However, if I need to modify the data(aggregate, transform etc), can I do it from the frontend using Ember? Or I need to write this code in Django and somehow call it through from the frontend (perhaps using some kind of API exposed by Django) ? Is there a preferred approach?

It would be a great help if I could get answers to these questions.

Cheers,

Haider


#2

I’m working on a project with Django as the backend, and to tell you the truth, it’s a pain. Django is alright, but it just doesn’t make sense since you have to throw 3/4 of it out when working with a Single Page Application.

For example, we tried to use Django’s commenting system, but it was so heavily tied to the templating, that we had to roll our own, and couldn’t extend the built in one. This works fine and all, but now we need to create a simple Admin interface for comment moderation, this means creating additional endpoints. In the end Django is mainly for quick prototyping, but only if you don’t know Ember already :smile:.

I recommend Node as the backend of choice, especially if you are planning on doing any Real-time work. Look into socket.io, and other technologies. If you have to use Python as the backend, I’m sure there are other REST framework options.

Furthermore, models are only so helpful. I recommend trying MongoDB, which gives you JSON out of the box. Using Node/Express you can easily conform it to ED’s standard, and the document-storage format works well (we are regretting using PostgreSQL).


#3

Agree with knownasilya. Have you considered using Meteor.js or Derby.js as the server (although they are very intimately linked to client) framework. They are built over Node.js and suit perfectly for real time applications.


#4

I wanted to see what others in the community thought about django / etc

Here is my opinion (as unbias as humanly possible)

1.) if you need real-time I don’t think python and django are the best platform at this time. Until PEP 3156 is finished async support in python will land you in a world of confusion or half baked solutions (my very very limited experience with it by the way)

2.) I never use 3rd party apps (I assume you are talking about something like comments from django contrib?) -if your team or project requires a ton of these you might not go the ember way as non of them are specifically setup to use your REST api or a javascript framework. That said, I don’t think django is only useful because of the 3rd part apps => it’s python after all :slight_smile:

3.) I would need to learn more or see a concrete example. My experience with both would advise you don’t use those 3rd party libraries unless you can drop in a simple REST api over the top of the basic database models using something like django-rest-framework. At this point you would still need to write /rewrite the templates as handlebars != django templates

4.) can you provide an example for this? generically speaking … you can have the client (in ember) do some transformation / business logic and simply pass it to an API for backend validation/ persistence (but this might not be ideal depending on your app / use case)

My general advise for those looking at django is this

If you need realtime / socket.io stuff you will need something where the server is event driven (like node.js) -python just isn’t built with something like this out of the box

If you are doing CRUD or something like CRUD django + ember is still productive because (something like this)

  1. build you models and leverage the ORM
  2. pip install django-rest-framework and add a few views / serializers for the above models
  3. write the html templates with handlebars and precompile them for the client
  4. to avoid networking code (if you just have basic $.ajax / etc) use a library like ember-data + an adapter (I have one for django-rest-framework, tastypie also has one if you use that)

I’ve been very productive and happy with both together (plus if you prefer python and generally like white space aware languages you can use coffee instead of javascript).


#5

Thanks for the reply, Ilya! I had a feeling that I would run into the issues you have outlined. I did take a look at some of the node based options and have decided to use node, atleast for this project.

I was researching some NoSQL data bases and finally settled with MongoDB despite the truck load of hate chasing it. It is sad that PostgreSQL caused you trouble , but I am very thankful that you told this, as I was really inclined to go the PostgreSQL way at one point.

The best part however is that I ended up learning Django and still have much respect for it. :slight_smile:


#6

Eneko I did go through both these frameworks but neither of them claims to be production ready. Amazing as they might be, I cant risk hitting a wall midway through my project. :slight_smile:


#7

Thanks a lot Toran!! Even I was waiting to hear more responses before blunting this toppic. :smiley:

Yeah, I think I was trying to use an awesome tool for the wrong job.

That has given me a lot of clarity regarding these technologies. [quote=“toranb, post:4, topic:2750”] 4.) can you provide an example for this? generically speaking … you can have the client (in ember) do some transformation / business logic and simply pass it to an API for backend validation/ persistence (but this might not be ideal depending on your app / use case) [/quote]

I was talking about simple transormations like word counting, hate phrase removal etc. I get your point.

This is going to be my plan after finishing with this project. Django-Ember based website blitzkrieg!! :grin:
Finally, I am glad I learnt Django and I found the value it has to offer. Thanks a lot for the help!!