Este post es para escribir esta poesia que es casi declarativa.

tomado de

http://www.beardygeek.com/2010/09/python-decorators-for-djangonauts/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+BeardyGeek+(BeardyGeek.com)

 

from urlparse import urlparse
from django.http import HttpResponseRedirect

def refer_check(func):
    def decorate(request):
        referer = request.META.get('HTTP_REFERER', '')

        if referer == 'http://www.example.com':
            return func(request)
        else:
            return HttpResponseRedirect('/')
    return decorate

 

 

@refer_check
def my_view(request):
    ....
    return render_to_response('myview.html')