Hallo,
ich habe noch etwas getüftelt. Aber jetzt bin ich zu einem brauchbaren Ergebnis gekommen. Schade nur, dass ich bisher nicht herausgefunden habe, wie ich vernünftig debuggen kann, wo mir also Fehlermeldungen aus Python angezeigt werden.
env.html
HTML
<html>
<p>
<form action="env.py/?get1=abc&get2=cde" method="POST">
post1: <input type="text" name="post1"><br>
post2: <input type="text" name="post2"><br>
<input type="submit">
</form>
</html>
env.py
Python
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys, os
import cgitb;
import cgi
cgitb.enable() # Debugging für CGI-Skripte 'einschalten'
class GET:
dict = {}
def all(self):
get = os.getenv("QUERY_STRING")
if get:
args = get.split('&')
for arg in args:
t = arg.split('=')
if len(t)>1:
self.dict[t[0]] = t[1]
return self.dict
def get(self, name):
if self.dict.has_key(name):
return(self.dict[name])
else:
return ''
class POST:
dict = {}
def all(self):
post = sys.stdin.read()
if post:
args = post.split('&')
for arg in args:
t = arg.split('=')
if len(t)>1:
self.dict[t[0]] = t[1]
return self.dict
def get(self, name):
if self.dict.has_key(name):
return(self.dict[name])
else:
return ''
print "Content-Type: text/html; charset=utf-8\n"
print "<h1>args:</h1>"
print "<hr/>"
get = GET()
post = POST()
print 'get all: [%s]<br>' % str(get.all())
print 'post all: [%s]<br>' % str(post.all())
print 'get1: [%s]<br>' % get.get('get1')
print 'post1: [%s]<br>' % post.get('post1')
print 'get invalid: [%s]<br>' % get.get('invalid')
print 'post invalid: [%s]<br>' % post.get('invalid')
Alles anzeigen