web.py 框架

作者: sunshaoping | 来源:发表于2018-04-09 22:09 被阅读0次

一、web.py 简介

一个非常轻量级的Python web框架,作为一个开源项目,简单而且功能强大

二、web.py 安装

python2版本的可以直接使用命令

pip install web.py

python3版本可使用指定版本安装命令

pip install web.py==0.40-dev1

三、web.py测试

```

import web

# 路由

urls = (

    '/blog/\d+', 'blog',

    '/index', 'index',

    '/(.*)', 'hello',

)

# 注册项目app

app = web.application(urls, globals())

# 视图处理

class index:

    def GET(self):

        return 'index method'

class blog:

    def GET(self):

        return 'blog method'

    def POST(self):

        return 'blog post mothod'

class hello:

    def GET(self, name):

        if not name:

            name = 'world'

        return 'hello, ' + name +'!'

# 启动项目

if __name__ == "__main__":

    app.run()

```

使用命令:python 文件,项目启动

四、Web开发demo

1.URL映射

(1).URL完全匹配 (必须是完成配置的)

/index

(2).URL模糊匹配

/post/\d+

(3).URL带组匹配(可传递给相对应的函数处理)

/post/(\d+)

五、源码分析

简单地了解了下这个框架,具体的大家可以上其网站,链接:http://webpy.org/

相关文章

网友评论

    本文标题:web.py 框架

    本文链接:https://www.haomeiwen.com/subject/psswhftx.html