Alternate 2xx status codes?

13 views
Skip to first unread message

Kyle Schaffrick

unread,
Aug 25, 2008, 5:28:30 PM8/25/08
to cherryp...@googlegroups.com
I can't seem to find any docs about how to return a successful status
code other than 200 from my CherryPy handlers. I would like to be able
to return a "201 Created" code (optionally with a Location: header) and
a "204 No Content" code in the cases where they are appropriate.

I tried using an HTTPRedirect for the former but it balks at status
codes that aren't in the 300 range.

What's the appropriate way to accomplish this?

Thanks
-Kyle

Robert Brewer

unread,
Aug 25, 2008, 5:53:25 PM8/25/08
to cherryp...@googlegroups.com

cherrypy.response.status = "201 Created"
cherrypy.response.headers['Location'] = cherrypy.url(newid)

Alternately, you can supply an int (e.g. 201) and let CP write the
default Reason-Phrase (e.g. "Created") for you.


Robert Brewer
fuma...@aminus.org

Kyle Schaffrick

unread,
Aug 26, 2008, 12:54:51 AM8/26/08
to cherryp...@googlegroups.com

Beautiful, thank you!

-Kyle

Reply all
Reply to author
Forward
0 new messages