This Django app provides a suite of utilities to disable caching in template views.
- Python >= 3.9
- Django >= 3.2
-
Install the package via pip:
pip install django-never-cache
-
Add
django_never_cacheto yourINSTALLED_APPSinsettings.py:INSTALLED_APPS = [ ... "django_never_cache", ... ]
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"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"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"You can contribute to this project on GitHub.
- tox
- Golang >= 1.21
- Fork the repository.
- Create a new branch:
git checkout -b my-branch-name. - Install
pre-commitwithpre-commit installand make your changes. - Commit your changes:
git commit -am "Add some feature". - Push your branch:
git push origin my-branch-name. - Create a pull request.
To run the tests, run the following command:
toxThis project is released under the MIT License.