Search code examples
djangometeorddp

How to use django-ddp


I'm using django as backend. While reading stuff about meteor, i found django-ddp. I searched a lot, but I didn't get what django-ddp is for. I understood that you can use it to connect meteor to your django backend, but what is the use case?

How does the client connect to django and/or meteor? Does meteor have to run on the same server? How are the http requests handled?

Maybe a tiny example would help me to get this.

For me important: Can i use this to combine benefits of django and meteor?


Solution

  • Django DDP provides a Meteor compatible, realtime, latency compensated backend framework for Django (Python) models. It can also serve your Meteor frontend code (HTML/JS/CSS/...) allowing you to avoid using Meteor (and node.js) on the server, whilst serving regular Django views at the same time.

    Django is a respected web framework with a powerful object relational mapper (ORM), with support for schema migrations included by default. Django DDP is efficient and secure, using gevent to handle HTTP requests and manage concurrency at the process level, and multiple processes (across multiple hosts) to allow scaling-out to serve many clients simultaneously. WebSockets are handled using gevent-websocket. Combining these aspects with the realtime, latency compensated benefits of Meteor does indeed give you the advantages of both (unless you prefer to run node.js on your backend servers).

    If Django DDP is used to serve your Meteor app then the client (browser) will connect to Django DDP automatically. Otherwise, you can connect your Meteor app to Django DDP and use the Django DDP connection like this:

    if(Meteor.isClient) {
        Django = DDP.connect('http://ddp.example.com/');
        Tasks = new Mongo.Collection('myapp.Tasks', {connection: Django});
        Django.subscribe('Tasks', {
            onReady: function(error, result) {
                // Log each matching Task to the browser console in a table
                console.table(Tasks.find().fetch());
            }
        });
    }
    

    If you're serving your Meteor app from Django DDP then drop the DDP.connect line and omit the second parameter to new Mongo.Collection.

    You might find the Todos example app a useful place to start. It includes a full working example of how to write both the Meteor client app and the Django DDP server app.

    Disclaimer: I'm the author of Django DDP - sorry if parts of my answer sound like marketing guff but I'm just trying to answer the first part of the question.