|
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 脚本
-
Karrigell services 是一种 Python 脚本,它的每一个函数都匹配一个不同的 URL : foo.ks/bar 匹配 foo.ks 脚本中的 bar() 函数 ( 如果没有指定函数 , 默认使用 index() 函数 )
-
HTML inside Python 是另一种写 Python 脚本的方式,在运行时当遇到 print 语句就会把要输出的字符串发送给客户端浏览器
-
Python inside HTML 是一种非常像 ASP,JSP,PHP 的写法, Python 写在 HTML 页面 < 的 % %> 标记中
-
还可以直接使用 CGI 脚本:参见文档的 cgi module 章节
Python代码在一个包含HTTP环境,表单字段,自定义异常的命名空间下运行。当一个表单包括字段<INPUT name="myfield">,它的值可以在脚本中使用_myfield来得到。
在身份认证和Session方面,可以在脚本中使用两个叫做Authentication和Session的函数来处理。Authentication的第一个参数是一个测试函数,用来检查是否接受输入的AUTH_USER和AUTH_PASSWORD。Session()用来初始化一个session对象并设置或读取它的属性值或者得到一个session。
Include(file_or_script)函数在当前脚本插入脚本或者文件的输出结果;例如它可用在页头或者页尾。
777




被折叠的 条评论
为什么被折叠?



