A small JavaScript utility library for use with Django projects
JavaScript Python
Switch branches/tags
Nothing to show
#1 Compare This branch is 5 commits ahead, 5 commits behind Dimitri-Gnidash:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


dutils - Django JS Utils

dutils is a small utility library that aims to provide JavaScript/Django developers with a few utilities that will help the development of RIA on top of a Django Backend.

Reversing Django Urls from Javascript

Why is this useful

One of the pillars of Django is DRY principle and hardcoding your urls in Javascript is violating that principle.

Moreover, building parametrized urls on the fly is error-prone and ugly.

What is included

A snippet of Javascript implementation of Django reverse function that can be found in dutils.js

A management command js_urls to generate a list of all of your Django urls


1. Add django_js_utils to your python path and add the django_js_utils application to your INSTALLED_APPS (if you want to use the management command)

2. Set the path and file name to generate urls to inside your django settings file. Example:


3. Set the url namespaces or names to resolve - only names specified in this list will be resolved to the file Example:

URLS_JS_TO_EXPOSE = ['admin', 'another_namespace', 'a_url_name',]

4. Add dutils.js and urls routing Javascript file to every web page where you plan to use the reverse function (likely just include in your base.html template)


1. To generate a list of all available urls in the special format:

>>> python manage.js js_urls

To keep the list of urls up-to-date, it is recommended to include this command as part of the build process.

2. On the web page, reverse url as such:

>>> $.post(dutils.urls.resolve('time_edit', { project_id: 1, time_id: 2 }), ...

For more usage, see example.html


  1. Handle the unnamed Django urls that result in <> in urls.js file, but are not handled in Javascript resolver.
  2. Write unit tests
  3. Promote the code