Newbie and Page Re-Loading

Newbie and Page Re-Loading

Post by mosscliff » Sat, 05 May 2007 19:41:30

I am very new to this python world, but I do like the look of the
language / syntax, though I have had some problems with indenting
using a text editor.

I have managed to get my ISP to execute .py files on their server.

I have created a .py file and it does in fact do the various little
tasks I have asked it to do.

Now i need to get a bit more serious.

I wish to have a web page with a search form at the top and on
processing the form re-load my current page, but with the various
search results.

Do I just add my script name to the Action part of the Form and how
can I pass variables, other than form variables to each execution of
the script. If I have to use hidden form variables, how would I alter
them for each page.

I suppose I am looking for some sort of session management, but I have
not been able to track one down as yet. I am running on an ISP, with
no knowledge of python, so asking about getting packages loaded will
not be an option.

I have 'Python in a Nutshell', but it is a bit sparse on everyday web
page examples.

Any help with regard to simple examples or tutorials would be most



Newbie and Page Re-Loading

Post by Bruno Dest » Sun, 06 May 2007 02:00:03

mosscliffe a rit :

There's no shortage of smart code editor having a decent support for


your script's url would actually be better.

Since you're talking about redisplaying the page with results added, I
assume this page is dynamically created by another python script. If so,
you can put the form's generation in a function that will take
page-specific params and put them in the appropriate hidden fields. Then
just call that function from the script generating your web page.

Depends... But if it's just to know which page called the script, you
don't need sessions here.

I'm suppose your doing CGI scripts. I've seen some basic session
management for CGI somewhere, but that's mostly old stuff.

You can install packages in your own space - you'll just have to make
sure that there in your python path.

"everyday web pages examples" in Python usually imply a more
sophisticated framework and a long running process (think Zope, Django,
CherryPy, Pylons, mod_python, wsgi, fcgi etc...)


Newbie and Page Re-Loading

Post by mosscliff » Sun, 06 May 2007 03:15:55


Many thanks for your very helpful reply.

I am trying WingIDE Personal as an editor, up to now it seems OK.

My ISP is running Python 2.4.3 and does not know about mod_python.

I do not want to run a framework yet. I would like to understand
python at script level, before adding more aspects to learn, like

I think I get your idea about hidden fields and how to alter them.

My single page script should work something like this

Check if this is a Re-Load (HiddenField would not exist first time I
am assuming)
Display SearchSection with previous SearchRequest
If SearchRequest is True: Get and Display Results
Display TrailerHTMLandTrailerBody

.......... Wait for NewSearch or NextPage

Does the above make sense or is there a better way ?

How do I get the directory of my modules into the Python Path

Is there a lightweight Https Server I could run locally (WINXP), which
would run .py scripts, without lots of installation modifications ?



On 4 May, 18:00, Bruno Desthuilliers <bruno.


Newbie and Page Re-Loading

Post by Bruno Dest » Sun, 06 May 2007 05:48:33

mosscliffe a rit :

Few ISPs want to deploy mod_python...

Bottom-top approach, hu ?-)

Anyway, "the script level" can be a bit restrictive - you may at least
want to use modules and functions...

What do you call "previous search request" ?

This (almost) makes sens in this context. As far as I'm concerned, I'd
split this in:
- a module handling all search logic
- a module/script/whatever handling all the "display" logic
- a script calling on the first if necessary to get 'raw' search
results, then calling on the second (with whatever appropriate
parameters, including stuff like search results) and returning the result.

import sys

Don't know what it's worth, and it seems to have a serious limitation
(no possible redirect), but that may help testing your scripts. FWIW, a
cgi script can be directly called if you setup the correct environnement
vars and pass the correct args (which can be done from another script !-)

Newbie and Page Re-Loading

Post by Miki » Sun, 06 May 2007 06:10:11

Hello Richard,

The way CGI works is that your script is called every time the
corresponding HTML is loaded. You can access all the parameters sent
to the script using cgi.FieldStorage.

Note that hidden fields are passed in plain text format from/to the
server, don't send anything sensitive in them.

It could be None: cgi.FieldStorage().getvalue("hidden_attribute") ==

In CGI you don't wait, the script exists and called again when use
hits a button/refresh ...

There are many other ways (AJAX, Web frameworks, FastCGI ...). However
I'd recommend you start with plain CGI which is *simple*.
Here is a small example:

import cgitb; cgitb.enable() # Show errors in HTML output
from cgi import FieldStorage

FUNNY = [ "mickey", "donald", "daisy", "minnie", "goofy" ]

def main():
print "Content-Type: text/html"

form = FieldStorage()
query = form.getvalue("query", "")

print '''<html><body>
<h1>Disney Search</h1>

<input type="text" name="query" value="%s">
<input type="submit" value="search">
''' % query

if query:
for someone in FUNNY:
if query in someone:
print "<br />%s" % someone

print "</form></body></html>"

if __name__ == "__main__":

import sys

Note that your script directory is automatically added to the path. .
Make sure "mod_cgi" is uncommented, set your document root and set
right python interpreter in cgi.assign


Newbie and Page Re-Loading

Post by alea » Sun, 06 May 2007 11:42:26


For https, you do need to do substantial homework, though -- no two ways
about it, since you'll need to get SSL certificates, etc etc. There are
reasonably simple instructions for the purpose at
<http://www. ***
ration.html>, but they're for Linux -- I don't know how they change when
you want to serve https on Xp.


Newbie and Page Re-Loading

Post by mosscliff » Sun, 06 May 2007 17:50:46


Thank you very much for your helpful reply. A simple example is the
best way of getting started, I have found.

I have no excuses now - to not get it working. I recently tried
Visual Studio with Visual Basic. Nice for five minutes, but then all
the helping bits got in the way, so then you try to do it all yourself
and the logic behind 'viewstate' just seemed to do different things at
different times and my silver surfing brain, just wants to do things,
rather than learn all sorts of exceptions, which I will not remember
tomorrow, never mind the next week or month.

I will try the local server, after I get forms working.

A question for the future. I am creating several spreadsheets on
google which contain data, I need to search and display on my web
page. The data is quite large so I need to filter it as opposed to
just looking at the spreadsheet. Am I right in thinking there is
something called an 'atom' feed, which will supply me the data from
google as a 'cursor' (think it is an SQL term) and I can read the rows
as records in python ?

Thanks again


On May 4, 10:10 pm, Miki < XXXX@XXXXX.COM > wrote:
> sys.path.append("/path/to/my/modules")


Newbie and Page Re-Loading

Post by mosscliff » Sun, 06 May 2007 17:52:25


Thanks for the help.