zoukankan      html  css  js  c++  java
  • web.py利用模板的详细步骤

    python网络编程学习笔记(10):webpy框架》(http://www.cnblogs.com/xiaowuyi/archive/2012/11/15/2771099.html#3006443)的解释。

            网友@etfengyun近期提出疑问,在webpy0.33上利用模板时出现错误。由于我按@etfengyun的作法没有再现出错误,所以不好判断错误的原因,这里把具体利用模板的步骤再详细解释一下。

    1、环境:python2.7.x+webpy0.33(下载地址:http://webpy.org/static/web.py-0.33.tar.gz

    2、建立test文件夹,将webpy0.33解压出来的web文件夹存在放在test下,并建立testwebpy.py文件以及建立templates文件夹,在templates文件夹下,建立index.html文件,该文件内容为:

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

    3、testwebpy.py的代码:

    ##@小五义http://www.cnblogs.com/xiaowuyi
    import web
    render = web.template.render('templates/')
    urls = (
        '/', 'index'
    )
    
    class index:
        def GET(self):
            name='Bob'
            return render.index(name)
            #return "Hello, world!"
    
    if __name__ == "__main__":
        app = web.application(urls, globals())
        app.run()

    运行效果:

    代码2:

    ##@小五义http://www.cnblogs.com/xiaowuyi 
    import web 
    render = web.template.render('templates/') 
    urls = ( 
        '/(.*)', 'index' 
    ) 
    
    class index: 
        def GET(self,name): 
            i=web.input(name=None) 
            return render.index(name) 
            #return "Hello, world!" 
    
    if __name__ == "__main__": 
        app = web.application(urls, globals()) 
        app.run()

    运行效果:

  • 相关阅读:
    Python标准模块--logging
    Spark中决策树源码分析
    常见的相似或相异程度计算方法
    mpi4py实践
    集成学习
    决策树
    git使用
    Ubuntu 14.04 64bit 安装tensorflow(GPU版本)
    KNN算法
    一致性哈希算法原理及其在分布式系统中的应用
  • 原文地址:https://www.cnblogs.com/xiaowuyi/p/3911613.html
Copyright © 2011-2022 走看看