python web py官网_Python web.py模块基本应用

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号线

深圳地铁官网


请排队候车

  • 首页
  • 公司新闻
  • 运营服务
  • 规划建设
  • 物业开发
  • 招标招商

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值