On Nov 29, 8:28 pm, James Matthews <[email protected]> wrote: > Hi, > > When I use this rate > limiterhttp://www.levigross.com/post/1721427025/django-rate-limitingand > preform an > ajax request I get this error > > django/middleware/common.py", line 84, in process_response > if response.status_code == 404: > AttributeError: 'function' object has no attribute 'status_code' > > [CODE] > @ratelimit > @never_cache > def ajaxrequester(request): > if request.is_ajax(): > stuff = submitform(request.POST) > return HttpResponse("{'ok':200}",content_type="text/xml") > else: > return HttpResponseForbidden("You don't belong here") > [/CODE] > > Any thoughts?
It looks like that is a callable decorator - it is intended to be called immediately, with arguments: @ratelimit(limit=5) ...etc... You can tell it's meant to be used like this because of the extra level of nested functions: normal decorators just return a function (which calls the decorated function), but callable decorators return a function (the actual decorator) which itself returns a function. (Actually I'm not sure that 'callable decorator' is the right term here, but I can't think of a better one. Is there a canonical name for this sort of thing?) -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

