django-charsleft-widget is a custom widget that limits the number of characters that can be entered in a textarea field.
Installation
pip install django-charsleft-widget
External dependencies
jQuery - this is not included in the package since it is expected that in most scenarios this would already be available.
Setup
Add charsleft_widget to INSTALLED_APPS:
INSTALLED_APPS += (
'charsleft_widget',
)
and just include charsleft_widget templates
{% include "charsleft_widget/charsleft_widget_css.html" %} {# Before the closing head tag #}
{% include "charsleft_widget/charsleft_widget_js.html" %} {# Before the closing body tag #}
When deploying on production server, don’t forget to run:
python manage.py collectstatic
Usage
All you need now is to import ClearableInput class and override field’s widget, for example:
from django.forms.fields import CharField
from charsleft_widget import CharsLeftArea
class Form(forms.Form):
field = CharField(max_length=128, widget=CharsLeftArea)
Please see example application. This application is used to manually test the functionalities of this package. This also serves as a good example.
You need Django 5.2 or above to run that.
License
django-charsleft-widget is released under the BSD license.
Changes
1.1.0 (2026-08-14)
Added Django 6.0 and 6.1 support, alongside existing Django 5.2 support (fixes #7).
Dropped Python < 3.10 support.
Fixed charsleft.js: a page without both jQuery and a django global crashed with ReferenceError: django is not defined; typing past maxlength right on an emoji or other astral character split its UTF-16 surrogate pair and corrupted the field; only keyup/change were handled, so paste-via-mouse and IME input didn’t update the count; dynamically-added widgets (formsets, ajax) were never wired up; and the charsleft helper leaked onto window.
Fixed USE_JINJA rendering: textarea.jinja lived under templates/, where Django’s Jinja2 backend (APP_DIRS scans each app’s jinja2/ directory) could never find it; moved it to charsleft_widget/jinja2/.
Removed charsleft_widget/fields.py, a pre-Django-1.7 maxlength shim superseded by Django core and unused since.
locale/ and jinja2/ assets weren’t declared in package-data and were silently missing from built wheels/sdists; added.
Increased test coverage to 100%; added tests for Media, a value already over maxlength, and the Jinja2 backend actually being used.
Reformatted code and templates, and fixed ruff lint findings.
1.0.0 (2021-11-30)
Added Django 3+ support.
Dropped Python 2.7 support.
Dropped Django 1.10 / 1.11 support.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_charsleft_widget-1.1.0.tar.gz.
File metadata
- Download URL: django_charsleft_widget-1.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1efa922129a4e2c947bb0dc0e357693609a1bead25e1ce8ee0eb323be7475082
|
|
| MD5 |
0d4970bd9fd7f2d868522c600b91c53a
|
|
| BLAKE2b-256 |
c8c79fe0fbb71f07cb66fac0d87773fabf7e7c90b5166848076ee221baf1fd98
|
Provenance
The following attestation bundles were made for django_charsleft_widget-1.1.0.tar.gz:
Publisher:
release.yml on bashu/django-charsleft-widget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_charsleft_widget-1.1.0.tar.gz -
Subject digest:
1efa922129a4e2c947bb0dc0e357693609a1bead25e1ce8ee0eb323be7475082 - Sigstore transparency entry: 2465956684
- Sigstore integration time:
-
Permalink:
bashu/django-charsleft-widget@d662397694e68147a1aead99f13afb05eace3056 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/bashu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d662397694e68147a1aead99f13afb05eace3056 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_charsleft_widget-1.1.0-py3-none-any.whl.
File metadata
- Download URL: django_charsleft_widget-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a500958b1c209bb148da1ef314e9b6d0b8d456233aa2cd8248ac0a37e8dd51f
|
|
| MD5 |
88abeff2a6f89f7f301bdd7c821d5d0d
|
|
| BLAKE2b-256 |
8650fd03c549f822f3af6055aae03b0a9d54202974e6a15844636f9a79a647e5
|
Provenance
The following attestation bundles were made for django_charsleft_widget-1.1.0-py3-none-any.whl:
Publisher:
release.yml on bashu/django-charsleft-widget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_charsleft_widget-1.1.0-py3-none-any.whl -
Subject digest:
1a500958b1c209bb148da1ef314e9b6d0b8d456233aa2cd8248ac0a37e8dd51f - Sigstore transparency entry: 2465956717
- Sigstore integration time:
-
Permalink:
bashu/django-charsleft-widget@d662397694e68147a1aead99f13afb05eace3056 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/bashu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d662397694e68147a1aead99f13afb05eace3056 -
Trigger Event:
push
-
Statement type: