Python web.py模塊基本應用css
系統版本:CentOS release 6.5html
安裝pip:yum install python-pippython
安裝web:pip install webweb
主要以配置文件爲主進行瀏覽器
一、入門配置app
[root@IDC-105 erweima]# cat weixin.pyurl
# -*- coding:utf-8 -*-spa
import web.net
urls = ( #定義路由,用戶訪問界面3d
'/','Index' #首頁,首頁指向
)
class Index(object):
def GET(self):
print "已檢測到,頁面有用戶訪問" #瀏覽器返回打印信息
return "Welcome to My WebSite" #瀏覽器獲取的界面信息
if __name__ == '__main__':
web.application(urls,globals()).run()
執行腳本,驗證結果
二、增長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
頁面查看
三、附件
自行上傳圖片
瞭解基本html知識
[root@IDC-105 erweima]# cat templates/index.html
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<title> web test </title>
<style type="text/css">
.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:"微軟雅黑";}
</style>
</head>
<body>
<div class="shou">
<h1>歡迎來到深圳地鐵1號線</h1>
<a href="http://www.szmc.net/page/index.html" class="sh1">深圳地鐵官網</a>
</div>
<hr>
<h2>請排隊候車</h2>
<div class="box">
<ul>
<li>首頁</li>
<li>公司新聞</li>
<li>運營服務</li>
<li>規劃建設</li>
<li>物業開發</li>
<li>招標招商</li>
</ul>
</div>
<img src="/static/images/zuomian.jpg" width=200px height=100px />
</body>
</html>