-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsk.py
48 lines (43 loc) · 1.1 KB
/
Ask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from cgi import parse_qs,escape
def application(environ, start_response):
start_response('200 OK',[('Content-Type','text/html')])
res="""
<html>
<head>
<title>Get and Post parameters</title>
</head>
<body>
"""
res+="<h1>Hello cruel world!</h1>\n"
#GET form
res+="""<h2>GET</h2>\n<ol>
<form action="" method="get">
<input type="text" name="name" />
<input type="text" name="surname" />
<input type="submit" value="Send"/>
</form>
"""
#parsim query string, polychaem parametry
d=parse_qs(environ['QUERY_STRING'])
for k in d:
res += "<li>%s = " % k
for v in d[k]:
res += "%s</li>" % v
# analogichno
res+="""</ol>\n<h2>POST</h2>\n<ol>
<form action="" method="POST">
<input type="text" name="name" />
<input type="text" name="surname" />
<input type="submit" value="Send"/>
</form>
"""
p=parse_qs(environ['wsgi.input'].readline())
for name in p:
res += "<li>%s = " % name
for val in p[name]:
res += "%s<br></li>" % val
res += """</ol>
</body>
</html>
"""
return res