django-js-urls
Django-js-url is a lightweight Django application allowing to easily get absolute path references matching given URL names and optional parameters on the client side - just like reverse does, but in a Javascript fashion.
Main requirements
Python 3.4+, Django 1.11+.
Installation
To install Django-js-urls, please use pip (or pipenv) as follows:
$ pip install django-js-urls
Once installed you just need to add js_urls to INSTALLED_APPS in your project’s settings module:
INSTALLED_APPS = (
# other apps
'js_urls',
)
URLs that are included in the Javascript helper tool are configured using a single JS_URL setting. This setting can embed URL namespaces or specific URL names that should be included in the generated Javascript file. For example:
JS_URLS = (
'admin',
'blog:article_list',
'blog:article_detail',
)
Important: only URLs defined in this setting will be included in the generated Javascript file. You don’t want to expose all the URLs of your Django project in a Javascript file.
Then you can include the view responsible for generating the Javascript file in your URLs root module:
from js_urls.views import JsUrlsView
urlpatterns = [
# other urls
url(r'^js-urls/$', JsUrlsView.as_view(), name='js_urls'),
]
And finally you can include the Javascript script in your base template as follows:
<script src="{% url 'js_urls' %}" type="text/javascript"></script>
Usage
URLs included in the generated Javascript file can be used in your scripts by using the window.reverse function. Here are some example:
const url1 = window.reverse('home');
const url2 = window.reverse('blog:article_list');
const url3 = window.reverse('blog:article_detail', articleId);
const url4 = window.reverse('blog:article_detail', [articleId, ]);
const url5 = window.reverse('blog:article_detail', { pk: articleId });
License
MIT. See LICENSE for more details.
Metadata
Release files for django-js-urls 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-js-urls-0.1.1.tar.gz | 7.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_js_urls-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 15.9 kB
Release files / django-js-urls-0.1.1.tar.gz
| Download URL | django-js-urls-0.1.1.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e578a1dae530968ea1c3d609a9177c7fe7bbc2774e5e61dcb2da4b311527cce
|
|
BLAKE2b-256 checksum How to use checksums |
a777b466e0974cccdc620c3e501e92b0e6644cb4961c70cd8e006aa95eed36aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Release files / django_js_urls-0.1.1-py2.py3-none-any.whl
| Download URL | django_js_urls-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c51660f5f7ab22037e91ce161e4e74405bc2ee714573ce762899ef73c5d818a8
|
|
BLAKE2b-256 checksum How to use checksums |
53424fedb83272adf43d1e4a5aba807adc366634c6914abed577b4f22e262cb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|
Security for django-js-urls 0.1.1
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.