skip to navigation
skip to content

django.js 0.1.2

Django JS Tools

Latest Version: 0.8.1

Django.js provides tools for JavaScript developpement with Django. This is currently a work in progress so don’t expect it to be perfect.

Django.js is inspired from:


You can install Django.JS with pip:

$ pip install django.js

or with easy_install:

$ easy_install django.js

Add djangojs to your settings.INSTALLED_APPS.

Add djangojs.urls to your root URL_CONF:

urlpatterns = patterns('',
    url(r'^djangojs/', include('djangojs.urls')),

Template tags


You can either:

  • load the template tag lib into each template manually:
{% load js %}
  • load the template tag lib by adding to your
from django.template import add_to_builtins




A {% verbatim %} tag is available to ease the JS templating. It escape a specific part. For example, you may want a subpart of your template to be rendered by Django :

<script type="text/x-handlebars" id="tpl-django-form">
        {% verbatim %}
            {{#if id}}<h1>{{ id }}</h1>{{/if}}
        {% endverbatim %}
        {{ yourform.as_p }}


A {% django_js %} tag is available to provide the Django JS module. After loading, you can use the Django module to resolve URLs and Translations:

{% django_js %}
    $(Django).on('ready', function() {
            Django.url('my-view', 'arg1'),
            Django.url('my-view', ['arg1']),
            Django.url('my-view', {key: 'test'}),
            Django.trans('my string')
    Django.init({% django_urls_json %});

If you don’t want to manually trigger initialization, you can use the {% django_js_init %} tag:

{% django_js_init %}
    $(Django).on('ready', function() {

django_js tag also configure jQuery.ajax to handle CSRF tokens.


The {% jquery_js %} tag only load the jQuery (1.8.2) library.

The django_js and django_js_init tags automatically load jQuery so no need to manually load it.


The js_lib tag is a quick helper to include javascript files from {{STATIC_URL}}js/libs:

{% js_lib "my-lib.js" %}

is equivalent to:

<script type="text/javascript" src="{{STATIC_URL}}js/libs/my-lib.js"></script>
File Type Py Version Uploaded on Size
django.js-0.1.2.tar.gz (md5) Source 2012-10-01 89KB