Skip to content

Instantly share code, notes, and snippets.

@froi
Last active August 25, 2016 17:06
Show Gist options
  • Save froi/1037fd1b50a7a44d61eee9b4dc0151e7 to your computer and use it in GitHub Desktop.
Save froi/1037fd1b50a7a44d61eee9b4dc0151e7 to your computer and use it in GitHub Desktop.
Decorator for DRF to mark a view function as excluded from a list of api versions.
from rest_framework.exceptions import NotFound
def not_available_api_version(excluded_api_versions=None):
def decorator(func):
@wraps(func)
def wrapper(x, request, *args, **kwargs):
if excluded_api_versions and request.version in excluded_api_versions:
raise NotFound(detail=None)
return func(x,request, *args, **kwargs)
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment