Django URL Exposure to Javascript
Project description
==========================
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
Installation
************
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::
URLS_JS_GENERATED_FILE='static/js/dutils.conf.urls.js'
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 entries into your base.html template (or where ever you need) to include the dutils.js file, along with the dutils.conf.urls.js patterns file. If you're using Django's staticfiles app, you'll use something
like::
<script type="text/javascript" src="{{STATIC_URL}}dutils.js"></script>
<script type="text/javascript" src="{{STATIC_URL}}dutils.conf.urls.js"></script>
Usage
*****
1. Generate a list of all available urls in the special
format::
>>> python manage.py 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. If you're using Django's staticfiles app, issue the collectstatic command to include dutils.js and the urls list you generated in step 1 in your static
directory::
>>> python manage.py collectstatic
3. 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
TO-DO
------
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
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
Installation
************
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::
URLS_JS_GENERATED_FILE='static/js/dutils.conf.urls.js'
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 entries into your base.html template (or where ever you need) to include the dutils.js file, along with the dutils.conf.urls.js patterns file. If you're using Django's staticfiles app, you'll use something
like::
<script type="text/javascript" src="{{STATIC_URL}}dutils.js"></script>
<script type="text/javascript" src="{{STATIC_URL}}dutils.conf.urls.js"></script>
Usage
*****
1. Generate a list of all available urls in the special
format::
>>> python manage.py 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. If you're using Django's staticfiles app, issue the collectstatic command to include dutils.js and the urls list you generated in step 1 in your static
directory::
>>> python manage.py collectstatic
3. 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
TO-DO
------
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-js-utils-ng-0.5.futu.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0796e959bd6c40cbfdd5d96643c68539845803bedf3bea3e6481d1cbe6376054 |
|
MD5 | 7dc9ec14800649aa992e77910a2801c3 |
|
BLAKE2b-256 | e6ddad3a7f5a209a23b1b2242b98bfa57cb5873f4643e8eed94f67e76a0f6a3a |