django-whiff
django-whiff is a simple Django template tag that combines the functionality of the with and if tags, inspired by the Python walrus operator (:=). It allows you to assign a variable and immediately check if it is truthy, rendering content if it is.
Example
{% load whiff %}
{% whiff current_user as user %}
<h1>Welcome back, {{ user.first_name }} {{ user.last_name }}!</h1>
<p>Your last login was on {{ user.last_login|date:"F j, Y, g:i a" }}.</p>
<h2>Your Profile</h2>
<ul>
<li>Email: {{ user.email }}</li>
<li>Joined: {{ user.date_joined|date:"F j, Y" }}</li>
<li>Bio: {{ user.bio }}</li>
</ul>
{% endwhiff %}
Features
- Combines
withandifin a single template tag. - Simplifies template logic by reducing the need for nested tags.
- Easy to use and integrate into existing Django projects.
Caveats
- Not a great contender to replace multiple pipes or conditions in an existing template tag
Installation
You can install django-whiff via pip:
pip install django-whiff
Usage
Once installed, add django_whiff to your INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
...
'django_whiff',
...
]
Note the underscore, not hyphen.
How It Works
- The
whifftag assigns the value ofsome_objtoobj. - If
some_objis truthy, the content inside thewhiffblock is rendered. - If
some_objis falsey, nothing is rendered.
Tests
python -m unittest discover -s tests
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
Acknowledgements
Inspired by the Python walrus operator (:=) and the need for cleaner, more concise template logic.
Metadata
Release files for django-whiff 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 | Actions |
|---|---|---|---|---|
| django_whiff-0.1.1.tar.gz | 5.7 kB | Without provenance | Details for django_whiff-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_whiff-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for django_whiff-0.1.1-py3-none-any.whl |
Total release size: 9.9 kB
Release files / django_whiff-0.1.1.tar.gz
| Download URL | django_whiff-0.1.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
748199d2e81948bde4b7018ab39f65fc355e9d817f4c711f80ee8c9ced908a9a
|
|
BLAKE2b-256 checksum How to use checksums |
68ff78f2a1019ea081b2c6ed4a1859ec6cb23565b1da52ddf2dac6c926dec811
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Release files / django_whiff-0.1.1-py3-none-any.whl
| Download URL | django_whiff-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef52ca3099d98027ab80212f3a0fcbc1ed4d36f8db418d626f19d34d61ddd96e
|
|
BLAKE2b-256 checksum How to use checksums |
d3200d655cbe0f881423cfa73589985d4de6c854702148e855e6603acec505f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Security for django-whiff 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.