(newbie)cgi-problem

Anders Dahlqvist dahqlvist at sundsvall.mail.telia.com
Fri Jun 6 09:29:15 EDT 2003


I'm a total newbie to cgi-programming in python, so please bear with me.
I've written a script (see below) that doesn't do what I want it to, i.e
work as a standalone program
------------------funktioner.py--------------------------------------------------------------
#!/usr/bin/env python



import os,time,cgi,cgitb
from data import * 

cgitb.enable()


def htmlstart(titel):
        print  htmlhuvud % (titel, titel, time.strftime("%F %X",time.localtime()))

def htmlstop():
        print htmlslut




def tabell(typ):
        if typ in lista0:
                tabellhuvud="<TABLE BORDER=1><TR><TH>databas</TH><TH>url</TH></TR>"
                html=os.popen("mysql --host=loke --user=apache arbeten --exec='select
databas,url from rekrytering where %s=1'" % typ).readlines() 
        elif typ in lista1:
                tabellhuvud="<TABLE
BORDER=1><TR><TH>databas</TH><TH>url</TH><TH>email</TH></TR>"
                html=os.popen("mysql --host=loke --user=apache arbeten --exec='select
databas,url,email from rekrytering where %s=1'" % typ).readlines()
        print tabellhuvud
        #Skapa en ny lista, innehållande listor med  varje rad i en egen lista
        lista=[]
        for rad in html:
                resrad=rad.replace('\n','')
                nyrad=resrad.split("\t")
                lista.append(nyrad)

        
        if typ in lista0:
                for underlista in lista[1:-1]:#Första raden ingår i tabellhuvud
                        print "<TR><TD>%s</TD><TD><A HREF='%s'>%s</A></TD></TR>" %
(underlista[0],underlista[1],underlista[1])
        elif typ in lista1:
                for underlista in lista[1:-1]:
                        print "<TR><TD>%s</TD><TD><A HREF='%s'>%s</A></TD><TD><A
HREF='mailto:%s'>%s</A></Td></TR>" %
(underlista[0],underlista[1],underlista[1],underlista[2],underlista[2])
        print tabellslut

---------------------funktioner.py-------------------
The problem i have that it doesn't work as  a standalone program(i.e it
doesn't recognize the variables titel and typ), when i try to access it via
http://81.228.27.158/cgi-bin/python/funktioner.py?titel=Inskick&typ=inskick
although it works when invoked from
http://81.228.27.158/cgi-bin/python/inskick.py (code below)
---------------inskick.py----------------------------
#!/usr/bin/env python 

import funktioner

titel="Inskick"
typ="inskick"

funktioner.htmlstart(titel)
funktioner.tabell(typ)
funktioner.htmlstop()
----------------inskick.py-----------------------
What am I doing wrong here?

Best regards

Anders Dahlqvist
--
In a minimum-phase system there is an inextricable link between
frequency response, phase response and transient response, as they
are all merely transforms of one another.  This combined with
minimalization of open-loop errors in output amplifiers and correct
compensation for non-linear passive crossover network loading can
lead to a significant decrease in system resolution lost.  However,
this all means jack when you listen to Pink Floyd.





More information about the Python-list mailing list