PDA

View Full Version : Python question



GofBorg
22-Aug-2012, 22:35
I have a python script running under mod_python/Apache2 that performs some
searching on a small database. That part works brilliantly. It displays the
data just fine but I am trying to display the results in a slightly less
rudimentary form than what python dumps out by default. Ideally I would like
a link or button to start a new query. Problem is I can't seem to find a way
to have python generate a response page with embedded html or links. Anyone
have a link to a good resource for that?

Thanks.

Dave Howe
23-Aug-2012, 13:08
On 22/08/2012 22:35, GofBorg wrote:
> I have a python script running under mod_python/Apache2 that performs some
> searching on a small database. That part works brilliantly. It displays the
> data just fine but I am trying to display the results in a slightly less
> rudimentary form than what python dumps out by default. Ideally I would like
> a link or button to start a new query. Problem is I can't seem to find a way
> to have python generate a response page with embedded html or links. Anyone
> have a link to a good resource for that?

Normally, you are expected to supply the HTML yourself, in the body -
apache expects to get back a preformatted html page, and if it gets
plain text then ok, it can handle that, but its not what it wants or is
expecting.

I would expect therefore you to use print lines to send something like:

<html><head><title>Page Title</title></head>
<body><h1>Page Heading</h1>
<table border=1>
<th>Column one header</th>
<th>Column two header</th>

..... python code goes here, until you get to an output loop, then per-row:

<tr><td>Data column 1</td><Data column 2</td></tr>

...... then exit the loop and do:

</table><hr />
<form action="http://servername/pythonscriptname.py" method="get">
Argument one: <input type="text" name="arg1" value="" /><br />
Argument two: <input type="text" name="arg2" value="" /><br />
<input type="submit" value="button label"></form></body></html>

that should give you a nicely formatted table, and a submission form.
you can prepopulate the value fields to give the last submitted input if
you want too.

obviously a real-world page will usually be more complex than that, but
given I don't know your site, its hard to say what extra ornamentation
you need :)

GofBorg
23-Aug-2012, 22:01
Thanks Dave,

That was what I was trying to do but didn't understand how to
'print' the html codes. Makes sense now.