安装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中的赋值、浅拷贝、深拷贝介绍

和很多语言一样,Python中也分为简单赋值、浅拷贝、深拷贝这几种“拷贝”方式。 在学习过程中,一开始对浅拷贝理解很模糊。不过经过一系列的实验后,我发现对这三者的概念有了进一步的了解。...

PyTorch实现更新部分网络,其他不更新

torch.Tensor.detach()的使用 detach()的官方说明如下: Returns a new Tensor, detached from the current gra...

python base64库给用户名或密码加密的流程

给明文密码加密的流程: import base64 pwd_after_encrypt = base64.b64encode(b'this is a scret!') pwd_bef...

python中模块查找的原理与方法详解

前言 本文主要给大家介绍了关于python模块查找的原理与方式,分享出来供大家参考学习,下面话不多说,来一起看看详细的介绍: 基础概念 module 模块, 一个 py 文件或以其他文...

python分析网页上所有超链接的方法

本文实例讲述了python分析网页上所有超链接的方法。分享给大家供大家参考。具体实现方法如下: import urllib, htmllib, formatter website =...