Python script (hello.py)
|
Karrigell service (hello.ks)
|
print "Hello, world !"
|
def index(): print "Hello, world !" |
HTML Inside Python (hello.hip)
|
Python Inside HTML (hello.pih)
|
"Hello, world !"
|
Hello, world !
|
CGI script (hello.py in folder cgi-bin) |
|
print "Content-type: text/html" print "Hello, world !" |
|
如果要想像这样写一些Python代码的话,例如打印0到9的数字序列:
Python script
|
Karrigell service
|
print "<h1>Squares</h1>"
for i in range(10):
print "%s :<b>%s</b>" %(i,i*i)
|
def index():
print "<h1>Squares</h1>"
for i in range(10):
print "%s :<b>%s</b>" %(i,i*i)
|
HTML Inside Python
|
Python Inside HTML
|
"<h1>Squares</h1>"
for i in range(10):
"%s :<b>%s</b>" %(i,i*i)
|
<h1>Squares</h1>
<%
for i in range(10):
print "%s :<b>%s</b>" %(i,i*i)
%>
|
CGI script
|
|
print 'Content-type: text/html'
print
print "<h1>Squares</h1>"
for i in range(10):
print "%s :<b>%s</b>" %(i,i*i)
|
|
Python代码在一个包含HTTP环境,表单字段,自定义异常的命名空间下运行。当一个表单包括字段<INPUT name="myfield">,它的值可以在脚本中使用_myfield来得到。
在身份认证和Session方面,可以在脚本中使用两个叫做Authentication和Session的函数来处理。Authentication的第一个参数是一个测试函数,用来检查是否接受输入的AUTH_USER和AUTH_PASSWORD。Session()用来初始化一个session对象并设置或读取它的属性值或者得到一个session。
Include(file_or_script)函数在当前脚本插入脚本或者文件的输出结果;例如它可用在页头或者页尾。