status code 200---How to return

1,397 views
Skip to first unread message

monty808

unread,
Nov 3, 2009, 8:56:48 PM11/3/09
to web.py
Hi,

I need to return a status code of 200. How do I explicitly return
200?

Thanks

shwdai

unread,
Nov 3, 2009, 9:50:51 PM11/3/09
to webpy
return web.ok
 
 
2009-11-04

shwdai

发件人: monty808
发送时间: 2009-11-04  09:57:00
收件人: web.py
抄送:
主题: [webpy] status code 200---How to return

David Montgomery

unread,
Nov 3, 2009, 9:54:18 PM11/3/09
to we...@googlegroups.com
But  am returning a string as my html...how to I return twice?
--
David Montgomery
CEO
AdAloha
Honolulu, Hawaii 96815
808-351-5046
http://www.AdAloha.com
david.mo...@AdAloha.com

shwdai

unread,
Nov 3, 2009, 9:56:38 PM11/3/09
to webpy
You just directly return you html string, '200 OK' will automaticlly output before your html string as response header.
 
 
2009-11-04

shwdai

发件人: David Montgomery
发送时间: 2009-11-04  10:54:53
收件人: webpy
抄送:
主题: [webpy] Re: status code 200---How to return

shwdai

unread,
Nov 3, 2009, 9:57:28 PM11/3/09
to webpy
return web.ok(data=your_html_string)
 
 
2009-11-04

shwdai

发件人: David Montgomery
发送时间: 2009-11-04  10:54:53
收件人: webpy
抄送:
主题: [webpy] Re: status code 200---How to return

Anand Chitipothu

unread,
Nov 3, 2009, 10:10:47 PM11/3/09
to we...@googlegroups.com
2009/11/4 shwdai <shw...@gmail.com>:
> return web.ok(data=your_html_string)

web.ok is an exception. You should use it as raise web.ok(...).

You can also use:

web.ctx.status = "200 OK"
return "your-html"

David Montgomery

unread,
Nov 3, 2009, 10:23:31 PM11/3/09
to we...@googlegroups.com
Not working

error: 'module' object has no attribute 'ok'

return web.ok        
return html

So...how to I do this?

Thanks



2009/11/4 shwdai <shw...@gmail.com>

Anand Chitipothu

unread,
Nov 3, 2009, 10:27:34 PM11/3/09
to we...@googlegroups.com
2009/11/4 David Montgomery <davidmo...@gmail.com>:

> Not working
>
> error: 'module' object has no attribute 'ok'
>
> return web.ok
> return html
>
> So...how to I do this?

What is the version of web.py that you are using?

David Montgomery

unread,
Nov 3, 2009, 10:33:38 PM11/3/09
to we...@googlegroups.com
3.2

David Montgomery

unread,
Nov 5, 2009, 10:02:58 AM11/5/09
to we...@googlegroups.com
Is there not a way to return a status code?  Given I am returning a html string...how to I return a status code?

Angelo Gladding

unread,
Nov 7, 2009, 2:24:48 PM11/7/09
to we...@googlegroups.com
All will respond with an HTTP status code of "200 OK". Works on .32:

def GET(self):
  return 'implicit 200'

def GET(self):
  web.ctx.status = '200 OK'
  return 'explicit 200'

def GET(self):
  raise web.OK('explicit 200')

You shouldn't be receiving an AttributeError when calling OK if you've simply imported web.py standalone (`import web`).

If you are having a problem sending raw HTML you might find that you need to send an explicit HTTP Content-Type header using:

web.header('Content-Type', 'text/html')

or optionally define a character set:

web.header('Content-Type', 'text/html; charset=utf-8')

When rendering a template using a `web.template.render` object the header is automagically sent using the appropriate MIME (content) type based on the file being rendered (.html => text/html; charset=utf-8, .xhtml => application/xhtml+xml; charset=utf-8, .txt => text/plain — see line 820 in `template.py`).

Let me know if that helps.
--
Angelo Gladding
ang...@gladding.name
http://angelo.gladding.name/
E69E 47E8 5C3A 96E5 C70F
D931 F35C ACBA 6F39 9611
Reply all
Reply to author
Forward
0 new messages