web.py学习笔记

来源:互联网 发布:安纳金·天行者知乎 编辑:程序博客网 时间:2024/05/22 01:32

code.py

import web# render = web.template.render('E:\\py_demo\\py_demo\\templates')root = os.path.dirname(__file__)templatesPath=root+'\\templates\\'render = web.template.render(templatesPath)urls = (    '/(.*)', 'index')class index:    def GET(self,name):i = web.input(name=None)return render.index(i.name)if __name__ == "__main__":    app = web.application(urls, globals())    app.run()



tmplates/index.html

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


运行code.py
python code.py 127.0.0.1:8080
打开浏览器输入http://127.0.0.1:8080/?name=lin
得到I just wanted to say hello to lin.






0 0
原创粉丝点击