Skip to main content

A simple Django app to demonstrate never cache views.

Project description

Django Never Cache

This Django app provides mixins to disable caching for generic and login required views, and a middleware to disable caching for the whole site.

Prerequisites

  • Python >= 3.9
  • Django >= 3.2

Installation

  1. Install the package via pip:

    pip install django-never-cache
    
  2. Add django_never_cache to your INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        ...
        "django_never_cache",
        ...
    ]
    

Usage

NoCacheMixin

Use NoCacheMixin to disable caching for a view:

from django.views.generic import TemplateView
from django_never_cache.mixins import NoCacheMixin

class MyView(NoCacheMixin, TemplateView):
    template_name = "my_template.html"

PrivateAreaMixin

Use PrivateAreaMixin to require login and disable caching for a private area:

from django.views.generic import TemplateView
from django_never_cache.mixins import PrivateAreaMixin

class MyView(PrivateAreaMixin, TemplateView):
    template_name = "my_private_template.html"

NoCacheMiddleware

Use NoCacheMiddleware if you want to disable caching for the whole site:

MIDDLEWARE = [
    ...
    "django_never_cache.middleware.NeverCacheMiddleware",
]

If you have setted NeverCacheMiddleware in MIDDLEWARE you can exclude caching for a view using allow_cache decorator.

from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from django_never_cache.decorators import allow_cache

@method_decorator(allow_cache, name="dispatch")
class MyCachedView(TemplateView):
    template_name = "my_cached_template.html"

Contribute

You can contribute to this project on GitHub.

How to Contribute

  1. Fork the repository.
  2. Create a new branch: git checkout -b my-branch-name.
  3. Install pre-commit with pre-commit install and make your changes.
  4. Commit your changes: git commit -am "Add some feature".
  5. Push your branch: git push origin my-branch-name.
  6. Create a pull request.

Run tests

To run the tests, run the following command:

tox

License

This project is released under the MIT License.

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

django_never_cache-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

django_never_cache-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file django_never_cache-0.1.0.tar.gz.

File metadata

  • Download URL: django_never_cache-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for django_never_cache-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b2cd25940992a5c5660c4f4e51d97be5615ef6e7df5d8f62aba74d859c1e430
MD5 8125e0aeb1d362f8891b53e4760e78b9
BLAKE2b-256 da76ddf6ecfda38f9ee28182376951d578db1cb46c5d728e9acedfcce05b4350

See more details on using hashes here.

File details

Details for the file django_never_cache-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_never_cache-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e50ca7ad2ad92aee1a6a069e2e3eed4a2ce7457a5d2ed055026d9bb8bda9c59
MD5 93c2ec2cc9b86fc3c7260d13e1274866
BLAKE2b-256 82f32705dd075f7e1a89cc548e68c1a1cdd40b5aa3092f120cf43a219e1032ed

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