This is a decorator which essentially replaces the decorated view with a view that always raises Http404
(File Not Found) when settings.DEBUG
is set to True.
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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Excellent! Perfect timing --already using it.
#
Please login first before commenting.