Skip to main content

Revision info for Django static file

Project description

https://madewithlove.now.sh/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d https://badgen.net/pypi/v/dj-static-revision

Django plugin to provide a context variable for retrieving the version of running application.

This variable is meant to change the URL of a static file, to invalidate browser cache.

Install

python -m pip install dj-static-revision
# or
uv add dj-static-revision

Django Static Revision only supports Python 3.10+.

Usage

Add dj_static_revision.context_processors.static_revision to your context_processors list.

TEMPLATES = (
    {
        'NAME': 'jinja2',
        'BACKEND': 'django_jinja.backend.Jinja2',
        'OPTIONS': {
            'context_processors': (
                # Other context processors
                'dj_static_revision.context_processors.static_revision',
            ),

A variable REVISION will then exists in your template, you can use it to append to static file URL.

<script src="{{ static('js/app.js') }}?v={{ REVISION }}"></script>

Django Static Revision retrieves revision string from Git history. If your source code is not managed by Git, the revision info will be read from a file named .version placed next to manage.py file.

Settings

The revision string will be truncated to 10 characters. You can change that by add to Django settings:

STATIC_REVISION_STRING_LENGTH = 10

You can also change the file for Django Static Revision to read revision string from, by add this setting:

STATIC_REVISION_VERSION_FILE = '.version'

where .version is a text file containing any string you want.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_static_revision-0.10.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_static_revision-0.10-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file dj_static_revision-0.10.tar.gz.

File metadata

  • Download URL: dj_static_revision-0.10.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.8

File hashes

Hashes for dj_static_revision-0.10.tar.gz
Algorithm Hash digest
SHA256 8888a5ce8d0e330adf7777cad3d9834d4fd4ffa9ee8026db630c21209f5d43be
MD5 d12fd11ae7d0551fe49a9a1ec0dc0ab7
BLAKE2b-256 7f3eb5e570554cff1aacf53fbededadd21e75c98fc8dc74caf890316a1866f22

See more details on using hashes here.

File details

Details for the file dj_static_revision-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_static_revision-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 1b03885315b6b232aa2c90e829735398e10b66d07101a59428fc2954e3e56bc4
MD5 a6665e6f5adcada271352fab0bd5ed3c
BLAKE2b-256 918e4c3a1d6b55b67223cf0139e26d7e866e4899254936bc334a1158cede2131

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page