Simple ETag and Last-Modified mixins for class based views.
Django Conditional Views builds off of the built in django conditional view processing machinery to provide simple mixins for class based views that implement support for the ETag and Last-Modified conditional request headers.
Inherit one of these mixins to make your TemplateView's, DetailView's, or ListView's:
- Calculate and append ETag and/or Last-Modified headers to the response and;
- Respond with a 304 Not Modified or a 412 Precondition Failed to requests that provide conditional response headers such as If-Modified-Since
- Helpful Defaults
- ETags are automatically generated from the response.content.
- ETag generation can be customized both before and after the response is rendered.
- The Last Modified header is automatically set from the last modified timestamp of the template.
- In the case of the DetailView and ListView mixins, the Last Modified header may also be configured to get the last modification timestamp from a field on the model, in which case the lastest of that or the template's last modified timestamp will be used.
First install django-conditional-views
$ pip install django-conditional-views
Then inherit from one of the following mixins in your views:
- ConditionalGetMixin - Inherits from View
- ConditionalGetTemplateViewMixin - Inherits from TemplateView
- ConditionalGetListViewMixin - Inherits from ListView
- ConditionalGetDetailViewMixin - Inherits from DetailView
See the Usage and API sections of the documentation for more details.
Contributions are welcome.
To work on the Pendulum codebase, you'll want to clone the project locally and install the required dependencies via poetry.
$ git clone git@github.com:cordery/django-conditional-views.git
$ poetry develop
django-conditional-views uses pytest. To run tests:
$ pytest