安装Python的web.py框架并从hello world开始编程

yipeiwu_com6年前Python基础

最近有一个小的web项目,想用喜爱都python,但是想到之前接触过都django我感觉一阵不寒而栗,为什么?Django的配置太过复杂,而且小项目不太适合MVC的开发模式,所以我将目光转向了web.py这个小型web框架,并且真正让我动心都是其官方网站上都一句话:"Django lets you write web apps in Django. TurboGears lets you write web apps in TurboGears. Web.py lets you write web apps in Python." — Adam Atlas

最近切换了Ubuntu替换了Win7系统,所以这里介绍下Ubuntu都安装web.py
安装easy_install

sudo apt-get install python-pip

使用easy_install安装web.py

sudo easy_install web.py

测试是否安装成功:

在python shell中执行:

import web

如果没有报错则web.py安装成功. 下面开始我们第一个hello,world

import web

urls = ("/.*", "hello")        # 指定任何url都指向hello类
app = web.application(urls, globals()) # 绑定url

# 定义相应类
class hello:
def GET(self):
return 'Hello, world!'

if __name__ == "__main__":
app.run()

然后保存为hello.py并运行它

python hello.py

然后会看到输出:http://0.0.0.0:8080/

然后浏览器访问:http://localhost:8080即可看到 Hello, world! 我们第一个用python写的web程序就建立完成.

相关文章

python暴力解压rar加密文件过程详解

第一次使用csdn写文章,写得不好还请见谅。(运行环境:python3.6) 下了一个带密码的压缩包文件,作为一个刚学python的新手,想着能不能用python暴力破解它,于是在网上...

python 设置文件编码格式的实现方法

如果要在python2的py文件里面写中文,则必须要添加一行声明文件编码的注释,否则python2会默认使用ASCII编码。(python3已经没有这个问题了,python3默认的文件编...

如何在python字符串中输入纯粹的{}

python的format函数通过{}来格式化字符串 >>> a='{0}'.format(123) >>> a '123' 如果需要在文本中包...

python中迭代器(iterator)用法实例分析

本文实例讲述了python中迭代器(iterator)用法。分享给大家供大家参考。具体如下: #--------------------------------------- #...

python 实现网上商城,转账,存取款等功能的信用卡系统

python 实现网上商城,转账,存取款等功能的信用卡系统

一、要求 二、思路 1.购物类buy 接收 信用卡类 的信用卡可用可用余额, 返回消费金额 2.信用卡(ATM)类 接收上次操作后,信用卡可用余额,总欠款,剩余欠款,存款 其中: 1...