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

pip3 install dj-static-revision

Django Static Revision only supports Python 3.8+.

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.7.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: dj_static_revision-0.7.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Linux/6.5.0-35-generic

File hashes

Hashes for dj_static_revision-0.7.tar.gz
Algorithm Hash digest
SHA256 45ff9c59d9159bc9ec3d9add3093d4f3d4fdbf60da784ab5ce37662b221b7735
MD5 d457e49e6b541d388731079ddfaea11d
BLAKE2b-256 dbf59fd9f7426bf5175d8e056d4cb6bc8a289c9015f23daa00ebaae74172d068

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dj_static_revision-0.7-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Linux/6.5.0-35-generic

File hashes

Hashes for dj_static_revision-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3f0a0fe0890522c6625ccf497490e07c164de1879dd5f7a52c2961c9df93fa4f
MD5 5e39d71aff61baf9a460d9c27cdae68e
BLAKE2b-256 0681bd524da0bbd8e4796f430416a2373e997832ca5d7dc9df4811dd4b18cee7

See more details on using hashes here.

Supported by

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