码迷,mamicode.com
首页 > 编程语言 > 详细

Python web.py模块基本应用

时间:2017-02-18 20:08:48      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:text   font   elf   sel   div   int   css   alt   mil   

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

<!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>

Python web.py模块基本应用

标签:text   font   elf   sel   div   int   css   alt   mil   

原文地址:http://www.cnblogs.com/sunnyyangwang/p/6413790.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!