web.py python框架入门

index.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import web
import blog
render = web.template.render('templates/')
urls=(
    '/blog',blog.app_blog,
    '/','index',
)

class index:
    def GET(self):
        name='test'
        #i = web.input(name=None)
        return render.index(name)



if __name__ == "__main__":
    app=web.application(urls,globals())
    app.run()

blog.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import web
urls=(
    "","reblog",
    "/(.*)","blog",
)

class reblog:
    def GET(self):
        raise web.seeother("/")
class blog:
    def GET(self,path):
        return "blog"+path
app_blog=web.application(urls,locals())

/templates/index.html

$def with (name)

$if name:
    I just wanted to say <em>hello</em> to $name.
$else:
    <em>Hello</em>, world!

启动WEB的命令 python index.py,默认在8080端口

发表评论

电子邮件地址不会被公开。 必填项已用*标注