Use of print statements and input handling in colubrid vs web.py

15 views
Skip to first unread message

Anthony Baby

unread,
Mar 6, 2007, 6:22:42 AM3/6/07
to colubrid-users
I've been experimenting with Colubrid as an alternative to Web.py, but
the lack of full documentation and tutorials is slowing me down on
even some of the trivial tasks, the most basic being output. Under
Web.py I like using python's print to output to a web page. I prefer
this to building a string and then returning it. To illustrate:

def GET(self):
web.header("Content-Type", "text/html; charset=utf-8")
print header
print "<body>Hello World!</body></html>"

I can't seem to do this using Colubrid. Following the website examples
for a WebpyApplication, I've had to use the following:

def GET(self, name):
resp = HttpResponse()
resp['Content-Type'] = 'text/html'
resp.write(header)
resp.write('<body>Hello World!</body></html>')
print 'Hello World'
return resp

In the above example, "print" outputs to the terminal and not to the
webpage. My preference is to use print statements as opposed to
returning multiple writes(). Why am I not able to use print as I was
under web.py? Is there an alternative method? If not, what advantages,
if any, are there to the way Colubrid works?

Also, under web.py I would use web.input() under POST to retrieve and
work with form data. How do I accomplish this in a WebpyApplication or
a ResolveRegexApplication?

Regards,

Anthony

Armin Ronacher

unread,
Mar 10, 2007, 3:25:38 PM3/10/07
to colubri...@googlegroups.com
Hoi,

Anthony Baby wrote:
> I've been experimenting with Colubrid as an alternative to Web.py, but
> the lack of full documentation and tutorials is slowing me down on
> even some of the trivial tasks, the most basic being output. Under
> Web.py I like using python's print to output to a web page. I prefer
> this to building a string and then returning it. To illustrate:
>
> def GET(self):
> web.header("Content-Type", "text/html; charset=utf-8")
> print header
> print "<body>Hello World!</body></html>"
>
> I can't seem to do this using Colubrid. Following the website examples
> for a WebpyApplication, I've had to use the following:
>
> def GET(self, name):
> resp = HttpResponse()
> resp['Content-Type'] = 'text/html'
> resp.write(header)
> resp.write('<body>Hello World!</body></html>')
> print 'Hello World'
> return resp
>
> In the above example, "print" outputs to the terminal and not to the
> webpage. My preference is to use print statements as opposed to
> returning multiple writes(). Why am I not able to use print as I was
> under web.py? Is there an alternative method? If not, what advantages,
> if any, are there to the way Colubrid works?

No. colubrid does no thread magic. You have to use resp.write. Usually
you use template engines anyway so the lack of "print" shouldn't be a
problem.

> Also, under web.py I would use web.input() under POST to retrieve and
> work with form data. How do I accomplish this in a WebpyApplication or
> a ResolveRegexApplication?

request.args / request.form

Regards,
Armin

Graham Dumpleton

unread,
Mar 22, 2007, 11:04:47 PM3/22/07
to colubrid-users

On Mar 11, 7:25 am, Armin Ronacher <armin.ronac...@active-4.com>
wrote:

Or you do what I suggested in another thread earlier and use:

print >> resp, 'Hello World!'

Because the response object has a write() method it can be used like a
file object as argument to 'print'.

Graham

Reply all
Reply to author
Forward
0 new messages