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

yipeiwu_com5年前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 socket函数中,send与sendall的区别与使用方法

在python socket编程中,有两个发送TCP的函数,send()与sendall(),区别如下: socket.send(string[, flags])  发送TCP数据,返回...

python利用socketserver实现并发套接字功能

python利用socketserver实现并发套接字功能

本文实现利用python的socketserver这个强大的模块实现套接字的并发,具体内容如下 目录结构如下: 测试文件请放在server_file文件夹里面 server.py...

wxPython的安装与使用教程

wxPython的安装与使用教程

一、wxPython介绍     1.wxPython是Python语言的一套优秀的GUI图形库。wxPython可以很方便的创建完整的、功能键全的GUI用...

Pytorch 保存模型生成图片方式

三通道数组转成彩色图片 img=np.array(img1) img=img.reshape(3,img1.shape[2],img1.shape[3])...

pandas 将索引值相加的方法

如下所示: s1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']) s2 = pd.Series([10, 20, 30...