Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 29, 2010 20:28:10

James M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


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'


@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")

Any thoughts?



--http://www.goldwatches.com--

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Nov. 29, 2010 22:18:03

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


On Nov 29, 8:28 pm, James Matthews <nytrok...@gmail.com> 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'
>
>

> @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")
>
>
> 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 django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Nov. 30, 2010 14:44:24

David D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


On 29/11/10 22:17, Daniel Roseman wrote:


> (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?)

PEP 318 just says "function that returns a decorator" (which is a bit of
a mouthful)

"The current syntax also allows decorator declarations to call a
function that returns a decorator:"

...

"The rationale for having a function that returns a decorator is that
the part after the @ sign can be considered to be an expression (though
syntactically restricted to just a function), and whatever that
expression returns is called."

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 1, 2010 02:51:51

Andre T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


Noob question here: why would it need limit=5 if the funcion has default
values?


Best regards,
Andre Terra

On Mon, Nov 29, 2010 at 20:17, Daniel Roseman <dan...@roseman.org.uk> wrote:

> On Nov 29, 8:28 pm, James Matthews <nytrok...@gmail.com> 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'
> >
> >

> > @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")
> >
> >
> > 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 django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 2, 2010 23:38:59

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


On Dec 1, 2:43 am, Andre Terra <andrete...@gmail.com> wrote:
> Noob question here: why would it need limit=5 if the funcion has default
> values?

Even if it has a default value, you still need to call it to get your
decorator. As someone wrote above, its a function that returns a
decorator, not actually a decorator. So you could just do @ratelimit()
to use the defaults, but you need the brackets.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Dec. 3, 2010 00:50:27

Andre T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Error in ajax request


Ah, gotcha. What was I thinking? It's pretty obvious now :P

On Thu, Dec 2, 2010 at 21:37, pjrhar...@gmail.com <pjrhar...@gmail.com>wrote:

> On Dec 1, 2:43 am, Andre Terra <andrete...@gmail.com> wrote:
> > Noob question here: why would it need limit=5 if the funcion has default
> > values?
>
> Even if it has a default value, you still need to call it to get your
> decorator. As someone wrote above, its a function that returns a
> decorator, not actually a decorator. So you could just do @ratelimit()
> to use the defaults, but you need the brackets.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support