[Django]-How to use django-ddp

5👍

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.

👤Tyson

Leave a comment