JavaScript utilities for Django projects.
Project description
django-gesha ☕
JavaScript utilities for Django projects.
Current features:
- Easily add JavaScript context in class-based views and access it via a JavaScript API.
Many more features are planned ✍️.
Installation
Install to Python environment using pip
pip install django-gesha
Install app in Django project
Add gesha
to INSTALLED_APPS
in your Django project's
settings:
INSTALLED_APPS = [
...
"gesha",
]
Collect JavaScript assets
Run the
collectstatic
management command to collect django-gesha's JavaScript files. Django should locate
them automatically once the app is installed.
python manage.py collectstatic
Basic usage
Add mixin to class-based view
For example:
from django.views.generic import TemplateView
from gesha.mixins import JSContextMixin
class MyPage(JSContextMixin, TemplateView):
template_name = "myapp/mypage.html"
def get_js_context_data(self, **kwargs) -> typing.Dict:
context = super().get_js_context_data(**kwargs)
context.update({
"myNumber": 5,
"myString": "this is my string",
})
return context
Load django-gesha JavaScript assets in template
To use django-gesha's JavaScript API, load the script in your template, and load the
context using the jscontext
template tag:
{% load gesha static %}
{% jscontext %}
<script src="{% static 'gesha/dist/js/django-gesha.bundle.min.js' %}">
</script>
Test in JavaScript
Access the context data using the django
JavaScript API:
>> console.log(django.context.myNumber)
5
>> console.log(django.context.myString)
"this is my string"
Contributing
See Contributing.
License
MIT.
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
django-gesha-0.1a0.tar.gz
(99.5 kB
view hashes)
Built Distribution
Close
Hashes for django_gesha-0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 772f67334273b3686f5cfd0f0bd47172492256154aa7b34e1ba91daa0ce5c6c0 |
|
MD5 | 15559ec20642b761b74c0683db073b7e |
|
BLAKE2b-256 | 6451796c98734e7f3f5d55834386a5285c21490b6ea66f11c7d2797549ddbf5a |