python web.py

web.py

1.安装:

wget http://webpy.org/static/web.py-0.37.tar.gz

tar xvfz web.py-0.37.tar.gz

cd web.py-0.37

sudo python setup.py install

2.需求:

先说下需求,http://10.75.7.237:8080/?ipaddress=10.75.7.29&count=100 ,最终得到这个ip的日志的前100行

3.讲解:

#!/usr/bin/python

import web

render = web.template.render(‘templates/‘) 这是告诉你的web展现页面放在那个位置

urls = (

‘/‘, ‘index‘

)

这是告诉你访问/路径时所调用的类是index

class index:

def reset_sigpipe(self):

signal.signal(signal.SIGPIPE,signal.SIG_DFL)

def GET(self):

ip=web.input(ipaddress=None,count=None)  让url可以传输多个值名为ipaddress和count

print ip[‘ipaddress‘]

print ip[‘count‘]

a=ip[‘ipaddress‘]

address_dict={‘10.13.144.‘:‘bx‘,‘10.73.26.‘:‘tc‘,‘10.75.7.‘:‘yf‘,‘10.67.15.‘:‘yq‘}

aa=a.split(".")

b=aa[0:3]

d=aa[-1]

e=".".join(b)

c=e+"."

address_1=address_dict[c]

f=str(d)

g=address_1+f

time_day=time.strftime(‘%Y-%m-%d‘)

#h_1=subprocess.Popen(‘grep -R %s /data1/saelog/%s/error/‘%(g,time_day),shell=True,preexec_fn=self.reset_sigpipe(),stdout=subprocess.PIPE)

#h=h_1.stdout.read()

h = os.popen(‘grep -R %s /data1/saelog/%s/error/‘ % (g,time_day))

print h

head_list=[]

sum=0

dict={}

head_lines=ip[‘count‘]

print head_lines

if head_lines:

for i in h:

j=i.split(":")[1:]

head_list.append(j)

for kk in head_list:

dict[sum]=head_list[sum]

sum+=1

if sum == int(head_lines):

break;

dict_json=json.dumps(dict)

else:

for i in h:

j=i.split(":")[1:]

head_list.append(j)

for kk in head_list:

dict[sum]=head_list[sum]

sum+=1

dict_json=json.dumps(dict)

print dict_json

return render.index(dict_json)       传给页面展示的值

#return "Hello, world!"

if __name__ == "__main__":

app = web.application(urls, globals())

app.run()

templates目录下

index.html

$def with (name)

$if name:

$name    name为代码传过来的值

4.启动web.py

python test.py  后面不跟端口默认就是8080

5.访问http://10.75.7.237:8080/?ipaddress=10.75.7.29&count=100

时间: 2025-01-06 11:40:51

python web.py的相关文章

mac OS X 配置Python+Web.py+MySQLdb环境

MAC默认支持Python 2.7所以不用安装. 1.安装pip sudo easy_install pip 2.安装Web.py sudo pip install Web.py 3.安装MySQLdb sudo pip search MySQL_python sudo pip install MySQL_python 安装完成后建立软链 sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient

CentOS6.5环境中配置Python + Web.py + Apache部署环境

1. 安装apache:    yum install -y httpd httpd-devel     修改/etc/httpd/conf/httpd.conf中的servername等配置,使http://*:*/ 能正常访问 2. 安装python:    wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz        tar -xzvf Python-2.7.8.tgz    cd Python-2.7.8    

Python web.py模块基本应用

系统版本:CentOS release 6.5 安装pip:yum install python-pip 安装web:pip install web 主要以配置文件为主进行 1.入门配置 [[email protected] erweima]# cat weixin.py # -*- coding:utf-8 -*- import web urls = (    #定义路由,用户访问界面 '/','Index'  #首页,首页指向 ) class Index(object): def GET(s

Python Web.py与AJAX交互

好久没写博客,可能是懒,也可能是感觉自己以前写的东西蛮low,也便没有太大兴致来写Blog. 实训已经开始,希望自己在这段时间里思维水平.database.data mining.软件开发技术等等各个方面都能有质的提升.某次提升虽小,倒希望总结出自己的独特的东西,能吸引更多的读者. 这次要记录的东西,的确简单,AJAX的使用,http://www.w3school.com.cn/ajax/index.asp 这里W3C的教程已经讲的很细致,实例也具有ASP与PHP,大致一个普通人花不到半小时就可

web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100

对于中文编码的问题,总会出现各种各样恶心的错误,还不知道应该怎么解决,首先,你从最开头就应该关注编码问题,尽量保证所有的编码方式都是一致的 用python+web.py+mysql来写程序,首先要保证如下几个部分的编码都是对滴 主要包括如下几个部分: 1:python 写的程序, 统一用 utf-8 ,以及重新载入utf-8 2: web.py 的模板, 也就是html程序  统一保存格式为utf-8 , 并且html 申明 <meta http-equiv="Content-Type&q

每天一点python:web.py框架入门

在使用微信搭建公众平台的时候,使用的是web.py这个方便简单的框架,学习一下. 框架文档:http://webpy.org/docs/0.3/tutorial.zh-cn  按照文档的内容写一遍程序入门就没什么问题了 运行程序:cmd中--进入文件所在路径--输入 python 文件名即可运行 遇到的问题: 问题1.模板文件中,第一行必须以 $def with()开头,否则会报错 $def with (name) $if name: I just wanted to say <em>hell

python后端开发:高并发异步uwsgi+web.py+gevent

为什么用web.py? python的web框架有很多,比如webpy.flask.bottle等,但是为什么我们选了webpy呢?想了好久,未果,硬要给解释,我想可能原因有两个:第一个是兄弟项目组用webpy,被我们组拿来主义,直接用了:第二个是我可能当时不知道有其他框架,因为刚工作,知识面有限.但是不管怎么样,webpy还是好用的,所有API的URL和handler在一个文件中进行映射,可以很方便地查找某个handler是为了哪个API服务的.(webpy的其中一个作者是Aaron Swar

python+matplotlib+web.py

最近看了厦门大学数据库实验室林子雨老师的<大数据课程实验案例:网站用户行为分析>,可视化这块是用的R语言,我决定用Python来实现一下. 参考文献 http://dblab.xmu.edu.cn/post/7499/ 数据来源 http://pan.baidu.com/s/1nuOSo7B 1 # -*- coding: utf-8 -*- 2 """ 3 Created on Wed Apr 19 17:26:53 2017 4 5 @author: tour

Python开发WebService:REST,web.py,eurasia,Django

Python开发WebService:REST,web.py,eurasia,Django 博客分类: Python PythonRESTWebWebServiceDjango 对于今天的WebService开发,我们至少有两种选择:SOAP/WSDL/UDDI系列的: REST风格架构系列的 !!! 在Bioinformatics(生物信息学)领域,WebService是很重要的一种数据交换技术,未来必将更加重要.目前EBI所提供的WebService就分别有SOAP和REST两种方式的服务,