könnt ihr mir ein gutes Python CGI buch nennen,
dass sich auf _wirklich_ nur mit CGI beschäftigt?
mfg
Olf
PS: ich wusste nicht wo dieser beitrag rein sollte. bitte habt verständnis

is das das gemeinte englische buch?Internet Programming with Python
Guido Van Rossum et al - ??? Geschrieben vom Schöpfer der Sprache mit einer starken Betonung auf Internetprogrammierung, einschließlich HTML, CGI und generellen Sockets. Es besitzt auch am Anfang eine allgemeine Einführung in die Sprache .
Code: Alles auswählen
"""A cgi script that counts how many times the user has visited a web
site. A quick example on how to use cookies.
This script assumes that you have the Cookie module from Python 2.0.
If not, you might need to fiddle with it a bit --- not quite sure.
Author: Danny Yoo (dyoo@hkn.eecs.berkeley.edu)
"""
from Cookie import SimpleCookie
import cgi,cgitb;cgitb.enable()
import os
def getCookie(initialvalues = {}):
"""Return a SimpleCookie. If some of the cookie values haven't
been set, we'll plunk them into the cookie with the initialValues
dict."""
if os.environ.has_key('HTTP_COOKIE'):
C = SimpleCookie(os.environ['HTTP_COOKIE'])
else:
C = SimpleCookie()
for key in initialvalues.keys():
if not C.has_key(key):
C[key] = initialvalues[key]
return C
Code: Alles auswählen
>>> c=Cookie.SmartCookie()
/usr/local/lib/python2.3/Cookie.py:712: DeprecationWarning: Cookie/SmartCookie class is insecure; do not use it
DeprecationWarning)
Code: Alles auswählen
datei=open(text,'a')
Hi. Mach ruhig, es kann doch nix schaden...rolgal hat geschrieben:ich wage es ja fast nicht dich zu kritisieren
Nunja, als ich die Links zusammengestellt hab, wars schon lange her, da war Python 2.1 brandneurolgal hat geschrieben:...das gästebuch haben wir hier im forum schon mächtig verbessert und ausserdem verwendet er noch immer veraltete funktionen bzw. module.
Code: Alles auswählen
#!/usr/local/bin/python
import cgi
try:
form=cgi.FieldStorage()
name=form['name'].value
entry=form['eintrag'].value
name=cgi.escape(name)
entry=cgi.escape(entry)
result='<p><b>%s</b>schrieb:</p><p>%s</p>'%(name,entry)
target='/var/www/html/crossover/gaestebuch.txt'
f=file(target,'r')
content=f.read()
f.close()
result=result+content
f=file(target,'w')
f.write(result)
f.close()
print "Location: http://localhost/crossover/gaestebuch.shtml \n\n"
except:
print "Location: http://localhost/crossover/gaestebuch.shtml \n\n"
Code: Alles auswählen
puffer = cgi.FieldStorage()
print puffer["wert"].value