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
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
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