1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | def when_developing(view):
"""
Usage:
@when_developing
def delete_all_users(request):
User.objects.all().delete()
return HttpResponse('Successfully deleted all users.')
"""
from django.conf import settings
def f404(*args, **kwargs):
from django.http import Http404
raise Http404
def inner(*args, **kwargs):
return view(*args, **kwargs)
if not settings.DEBUG:
return f404
return inner
|
More like this
- View decorator to convert DoesNotExist (ObjectDoesNotExist) exceptions into Http404 exceptions by jammycakes 2 years, 7 months ago
- staff_or_404 Decorator by bkeating 6 months, 1 week ago
- Auto-resolving a specific object from key string in url with decorator by achimnol 2 years, 10 months ago
- cache_page that does nothing by peterbe 2 years, 9 months ago
- Expose the 404/500 views during development by andi 3 years, 9 months ago
Comments
Excellent! Perfect timing --already using it.
#