Python web.py模块基本应用
系统版本:CentOS release 6.5
安装pip:yum install python-pip
安装web:pip install web
主要以配置文件为主进行
1、入门配置
[root@IDC-105 erweima]# cat weixin.py
# -*- coding:utf-8 -*-
import web
urls = ( #定义路由,用户访问界面
'/','Index' #首页,首页指向
)
class Index(object):
def GET(self):
print "已检测到,页面有用户访问" #浏览器返回打印信息
return "Welcome to My WebSite" #浏览器获取的界面信息
if __name__ == '__main__':
web.application(urls,globals()).run()
执行脚本,验证结果
2、增加templates部署应用
a、增加templates
[root@IDC-105 erweima]# cat weixin.py
# -*- coding:utf-8 -*-
import web
urls = ( #定义路由,用户访问界面
'/','Index' #首页,首页指向
)
render = web.template.render('templates')
class Index(object):
def GET(self):
return render.index()
if __name__ == '__main__':
web.application(urls,globals()).run()
b、新增目录和文件
[root@IDC-105 erweima]# tree
.
├── static
│ └── images
│ └── zuomian.jpg
├── templates
│ └── index.html
├── weixin.py
└── weixin.pyc
页面查看
3、附件
自行上传图片
了解基本html知识
[root@IDC-105 erweima]# cat templates/index.html
web test.shou {width:60%;
height:60px;
background:#ccccff;
}
*{margin:0;padding:0;}
.box{width:100%;
height:200px;
background:#ffff33;
}
.box ul {width:100%;
height:40px;
background:black;}
.box ul li{
width:100px;
float:left;
list-style:none;
line-height:40px;
color:white;
font-family:"微软雅黑";}
欢迎来到深圳地铁1号线
请排队候车
- 首页
- 公司新闻
- 运营服务
- 规划建设
- 物业开发
- 招标招商