django-vrot
A collection of Django templatetags and middleware for common web development tasks.
Features
- Local timezone display: Automatically display dates and times in the visitor's local timezone
- Active link detection: Highlight active menu items based on current URL
- Query parameter management: Easily modify query parameters while preserving others
- Template utilities: Access dictionary items dynamically and format time displays
Installation
uv add django-vrot
Quick Start
- Add
vrotto yourINSTALLED_APPS:
INSTALLED_APPS = [
# ...
"vrot",
]
- For timezone support, add the middleware to your
MIDDLEWARE:
MIDDLEWARE = [
# ...
"vrot.middleware.TimezoneMiddleware",
]
- Include the JavaScript file in your base template (only needed for timezone features):
{% load static %}
<script src="{% static 'vrot/timezone.js' %}" defer></script>
Usage
Template Tags
Load the template tags in your templates:
{% load vrot %}
localtime - Display times in user's timezone
Renders a time element that will be converted to the user's local timezone via JavaScript:
{{ comment.created_at|localtime }}
Output:
<time datetime="2024-05-19T10:34:00+02:00" class="local-time">May 19, 2024 at 10:34 AM</time>
humantime - Human-friendly time display
Shows relative time for recent dates:
{{ comment.created_at|humantime }}
Outputs:
- "2 hours ago" (for times less than 24 hours ago)
- "Yesterday at 3:45 PM" (for times 24-48 hours ago)
- Full date display (for older times)
active_link - Highlight active menu items
<li class="{% active_link 'blog:index' %}">
<a href="{% url 'blog:index' %}">Blog</a>
</li>
Parameters:
viewname: The name of the view (including namespace, if any)css_class: CSS class to apply when active (default: "menu-active")css_inactive_class: CSS class when inactive (default: "")strict: If True, requires exact path match (default: False)
query_param_replace - Preserve query parameters
Useful for pagination while maintaining filters:
<a href="{% query_param_replace page=page_obj.next_page_number %}">Next Page</a>
This preserves existing query parameters (like filters) while updating the page number.
getitem - Access dictionary/list items
Access dictionary values with dynamic keys:
{{ my_dict|getitem:user_provided_key }}
Middleware
TimezoneMiddleware
Automatically activates the user's timezone based on a cookie set by the JavaScript code. This allows Django to render times in the user's local timezone server-side.
The middleware reads the timezone cookie and activates the corresponding timezone for the duration of the request.
How Local Timezone Display Works
- The included JavaScript sets a cookie with the user's timezone
- The
TimezoneMiddlewarereads this cookie and activates the timezone in Django - The
localtimefilter renders times with proper timezone information - The JavaScript converts any remaining times to the user's local format
For more details, see: https://www.loopwerk.io/articles/2025/django-local-times/
Requirements
- Django >= 3.2
- Python >= 3.9
License
MIT License - see LICENSE file for details.
Metadata
Release files for django-vrot 0.3.0
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_vrot-0.3.0.tar.gz | 7.9 kB | Without provenance | Details for django_vrot-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_vrot-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for django_vrot-0.3.0-py3-none-any.whl |
Total release size: 18.0 kB
Release files / django_vrot-0.3.0.tar.gz
| Download URL | django_vrot-0.3.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56edfed16b8e866077982538b02aa77e6832906b905b8fac6ee698ab30b863f6
|
|
BLAKE2b-256 checksum How to use checksums |
72db992c796ad1ff97dc4a2b4f38db20919d642a5752ce6a94ca1c1756afcee8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|
Release files / django_vrot-0.3.0-py3-none-any.whl
| Download URL | django_vrot-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a86702d859a5738026c98e0b0a54a03f84792310c04750d01c5f98063a1a61e5
|
|
BLAKE2b-256 checksum How to use checksums |
c490a1372926875ad1419cb36564d7e421e2b79b5f33fd50d8c61fd8b5a7ac99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|
Security for django-vrot 0.3.0
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.