On Oct 21, 1:15 am, "wyatt-bC" <[EMAIL PROTECTED]> wrote:
> On Oct 20, 9:25 pm, "wyatt-bC" <[EMAIL PROTECTED]> wrote:
>
>
>
> > askel wrote:
> > > wyatt-bC wrote:
> > > > Howdy. I'm doing some AJAXy stuff and I can't seem to get a status code
> > > > other than 200.
>
> > > > The relevant controller looks like this (sort of):
>
> > > >     def show(self, blah, blah):
> > > >         # do stuff and set ``code`` depending on what happens
> > > >         # ...
> > > >         return render_response('/service/%s.myt' % template, code=code)
>
> > > > Doesn't matter what I set ``code`` to. I always get status 200 back on
> > > > the client side.
>
> > > > I screwed around with middleware.py (turning different apps off) and
> > > > that didn't help.
>
> > > > Any ideas?
>
> > > response = render_response(template)
> > > response.status_code = code
> > > return response
>
> > Thanks. I ended up with this:
>
> > return render_response('/service/%s.myt' % template, status_code=code)OK, I 
> > thought it worked as a one-liner, but now it doesn't seem to be.
> Now I'm doing it the long way:
>
>             r = render_response(template, status_code=code)
>             r.status_code = code
>             return r
>
> There must have been some caching going on, because I tried the long
> way first, then changed it to the shorter way, then went away for a
> while, and then it stopped working.

And since I just can't get enough of this topic, here's why neither
``code`` nor ``status_code`` work as keyword args to render_response:

render_response hands its *args and **kwargs off to response to do some
work. The result from response is wrapped in a Response, but the
leftover keyword args aren't passed to the Response.

I would humbly propose that those leftover keyword args could/should be
passed on to Response, since render_response seems to be mainly a
convenience wrapper around Response, and doing so would create a
more-consistent API.

In my case, I happened to be looking through Paste a while back and saw
``code`` as an arg for Response (or WSGIResponse) and just assumed
passing Response args into render_response would work.

Blah blah blah..............
 
--
Wyatt Baldwin
byCycle.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss
-~----------~----~----~----~------~----~------~--~---

Reply via email to