Python web.py Module Basic Application
System version: CentOS Release 6.5
Installing Pip:yum Install Python-pip
Installing the Web:pip Install Web
Mainly based on the configuration file
1. Getting Started configuration
[email protected] erweima]# Cat weixin.py
#-*-coding:utf-8-*-
Import Web
URLs = (#定义路由, User Access interface
'/', ' index ' #首页, home point
)
Class Index (object):
def GET (self):
Print "detected, page has user access" #浏览器返回打印信息
Return "Welcome to My WebSite" #浏览器获取的界面信息
if __name__ = = ' __main__ ':
Web.application (urls,globals ()). Run ()
Execute script, Verify Results
2. Increase templates Deployment Application
a, Increase Templates
[email protected] erweima]# Cat weixin.py
#-*-coding:utf-8-*-
Import Web
URLs = (#定义路由, User Access interface
'/', ' index ' #首页, home point
)
Render = Web.template.render (' templates ')
Class Index (object):
def GET (self):
return Render.index ()
if __name__ = = ' __main__ ':
Web.application (urls,globals ()). Run ()
B. New directories and files
[email protected] erweima]# Tree
.
├──static
│└──images
│└──zuomian.jpg
├──templates
│└──index.html
├──weixin.py
└──weixin.pyc
Page view
3. Accessories
Upload images yourself
Learn basic HTML knowledge
[email protected]05 erweima]# Cat templates/index.html
<! DOCTYPE HTML public>
<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: "microsoft Jas black";}
</style>
<body>
<div class= "shou" >
<a href= "http://www.szmc.net/page/index.html" class= "sh1" > Shenzhen Metro official website </a>
</div>
<div class= "box" >
<ul>
<li> Home </li>
<li> Company News </li>
<li> Operations Services </li>
<li> Planning and Construction </li>
<li> Property Development </li>
<li> Invite Investment </li>
</ul>
</div>
</body>
Python web.py Module Basic Application