
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
django-rest-framework-condition
Advanced tools
Decorators @condition, @last_modified and @etag for Django Rest Framework
This package allows you to use @condition
decorator from Django on ViewSet or
APIView from Django Rest Framework. In other words, you can use http headers
ETag and Last-modified with you APIs.
It doesn't create custom implementation of etags or last-modified header but uses ones from Django which means you can be sure it will be updated by Django's authors.
Similarly as in Django you can use shortcut decorators @last_modified
and
@etag
.
Tested with:
pip install django-rest-framework-condition
Use decorators same way as with Django views.
Last-modified example
from datetime import datetime
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import last_modified
class LastModifiedApiView(APIView):
@last_modified(lambda _: datetime(2019, 1, 1))
def get(self, request):
return Response({'data': 'I have Last-Modified header!'})
ETag example
import hashlib
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import etag
def my_etag(request, *args, **kwargs):
return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()
class EtagApiView(APIView):
@etag(my_etag)
def get(self, request):
return Response({'data': 'I have Etag!'})
Both ETag and Last-Modified example
import hashlib
from datetime import datetime
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_condition import condition
def my_etag(request, *args, **kwargs):
return hashlib.md5(':'.join(request.GET.dict().values()).encode('utf-8')).hexdigest()
def my_last_modified(request, *args, **kwargs):
return datetime(2019, 1, 1)
class ConditionApiView(APIView):
@condition(etag_func=my_etag, last_modified_func=my_last_modified)
def get(self, request):
return Response({'data': 'I have both Last-Modified and Etag!'})
FAQs
Decorators @condition, @last_modified and @etag for Django Rest Framework
We found that django-rest-framework-condition demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.