Using python on the web

sp00fD sp00fD at yahoo.com
Tue Apr 18 05:00:48 EDT 2000


It's pretty easy really, to get the basics working at least.  In
general, this is about what you'd need

# For receiving data...
import cgi
query = cgi.FieldStorage()
# For each parameter we expect to be passed in we do
if query.has_key("ourparam"):
       result = query["ourparam"].value

# For printing pages, you could use the cgi module or just do it by hand
print "Content-type: text/html\n"
print "<HTML><HEAD><TITLE>Foobar</TITLE></HEAD>"
print "<BODY>"
import os
for k,v in os.environ.items():
        print "<B>%s => %s</B><BR>" % (k,v)
print "</BODY></HTML>"

For the database interaction, if you were using MySQL for instance, you
need to get the MySQLdb module
(http://starship.python.net/crew/adustman), build it, and then:

import MySQLdb
c = MySQLdb.connect(host="myhost", db="mydb", port=3316, user="me",
passwd="mypass")
con = c.cursor()
sql = "SELECT * FROM foo"
con.execute(sql)
rs = con.fetchall() # returns a tuple or list
c.close()


In article <MPG.1365adcfa8470eef9896aa at news>,
  Charley Horse <someone at somewhere.com> wrote:
> I've just started fooling with python. I've looked around the python
> site and a number of the other sites referenced there and am a bit
> puzzled. Umm... how does one go about using python for web
applications,
> especially database driven apps? Almost everything deals with python
> just as a language, as C++ would be. Not much about the web
> specifically. I was a bit shocked to find the only direct refs on
about
> this at python.org are entwined with CGI (unless I missed it). I have
no
> exposure to CGI, but rather to php, CF, and ASP, so python has gone
from
> looking very attractive to looking... well, like a puzzle. I know
about
> Zope, but am interested in how one uses python on the web just by
> itself.
>
> Thanks
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list