Skip to main content
django-serverpush
=================

Easy to use server push solution, highly integrated with django.

Requirements
------------

* Django
* Tornadio2

Introduction
------------

For any django view, you can define an update function by just naming it the
same as view function and appending "_update".

Lets say we have a view called hello that says hello to the user:

def hello(request):
return HttpResponse('Hey, %s!' % request.user.username)

Now we can define hello_update that returns what types of updates should affect
this page, and how will it be serialized:

* We can use default serializer and just define what fields we need:

def hello_update(request):
return [{'name':'username_change', 'model':User, 'params':{'pk':request.user.pk}, 'data':{'username':'object.username'}}]

But then we have to write a special bit of JavaScript to handle this:

$(document).bind('serverpush_username_change', function(event, data) {
$('body').html('Hey, ' + data.username + '!');
});

* We can write a custom serializer:

def hello_update(request):
# 'data' parameter is optional, and it is directly passed to the serializer
return [{'name':'reload', 'model':User, 'params':{'pk':request.user.pk}, 'serializer':hello_update_serializer}]

def hello_update_serializer(request, user, data):
return 'Hey, %s!' % user.username

And now we can either have a special JS for every page, or we can generalize
them a bit, and have just one or a few (name in the update function is name for
the JavaScript event).

$(document).bind('serverpush_reload', function(event, data) {
$('body').html(data);
});

In this example I called it reload, because all it does is swapping the HTML.

* Or we can just use hello view function for serializing:

def hello_update(request):
return [{'name':'reload', 'model':User, 'params':{'pk':request.user.pk}, 'serializer':'hello'}]

And change hello header a bit:

def hello(request, user=None, data=None):

And have one general JavaScript for the whole site / updates like that
(of course we can mix all three types of updates):

$(document).bind('serverpush_reload', function(event, data) {
$('body').html(data);
});

Why django-serverpush?
----------------------

Because it's super easy to use, and requires very little additional code to
transform a traditional django application.

Installation
------------

1. Install this package

sudo python setup.py install

2. Update settings.py

Add "serverpush" to INSTALLED_APPS and
"serverpush.client.context_processor" to TEMPLATE_CONTEXT_PROCESSORS.
Also add the following constants:

SERVERPUSH_PORT = 8013
SERVERPUSH_NOTIFIER_PORT = 8014
SERVERPUSH_GLOBALS = ()

3. Add a timestamp div to your template (for history to work)

<div id="generated_timestamp" style="display:none">
{{ generated_timestamp }}
</div>

4. Run it by calling ./manage.py runserverpush

Running Demo
------------

1. Create sqlite file

./manage.py syncdb

2. Run django development server

./manage.py runserver

3. Run serverpush server

./manage.py runserverpush

4. Navigate to localhost:8000 in multiple browsers/windows/tabs and observe the counter

Browser support
---------------

It's based on socket.io, so it should work in all major browsers.
Currently there are problems with opera (because it doesn't allow cross port
XHR, and JSONP makes it "load"), but I'm working on resolving them. Simple
solution would be to proxy XHR.

Metadata

Release files for django-serverpush 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-serverpush 2.1.0
File Size Uploaded Provenance Actions
django-serverpush.zip 11.1 kB Without provenance Details for django-serverpush.zip

Release files / django-serverpush.zip

Download URL django-serverpush.zip
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fbc8c6dbd3ef04e2bf3b0a72364f207c1f21fe7f53270bb04e22b37fe31fbe31
BLAKE2b-256 checksum
How to use checksums
6bcac7ebf0b64040c06ac7e2f3231ade227b641aa670a1d7df27c79ae01b4535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-serverpush 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page