python 第一个web程序
yum install python-setuptools
easy_install pip
pip install tornado
yum install MySQL-python
test.py里面的内容
#coding:utf-
import tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write('hello world') application = tornado.web.Application([(r'/',MainHandler),],debug=True) if __name__=='__main__':
tornado.options.parse_command_line()
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
#coding:utf-
import tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) mport tornado.web
import tornado.options
import tornado.ioloop from tornado.options import define,options
define('port',default=,help='run on the given port',type=int) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write('hello world') application = tornado.web.Application([(r'/',MainHandler),],debug=True) if __name__=='__main__':
tornado.options.parse_command_line()
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()class MainHandler(tornado.web.RequestHandler):
def get(self):
[root@iZ25vn32h9hZ mnt]# vi pythonSql.py
#coding:utf-
import tornado.web
import tornado.ioloop
import tornado.options
import MySQLdb from datetime import datetime,timedelta
from tornado.options import define,options
define('port',default=,help='run on given port',type=int) def readTxt():
global cpu,memory,disk,cache
f1 = open('../wuxi147_cpu.txt','r+')
f2 = open('../wuxi147_memory.txt','r+')
f3 = open('../wuxi147_disk.txt','r+')
f4 = open('../wuxi147_cache.txt','r+')
try:
cpu = int(float(cpu)*)
memory = '%.2f'%float(x[])
memory = int(float(memory)*)
print memory
x = f3.read().splitlines()
disk = '%.2f'%float(x[])
disk = int(float(disk)*)
print disk
x = f4.read().splitlines()
cache = '%.2f'%float(x[])
cache = int(float(cache)*)
print cache
finally:
f1.close()
f2.close()
f3.close()
f4.close() def saveInSql():
global cpu,memory,disk,cache
conn = MySQLdb.connect(host='localhost',port=,user='root',passwd='niot',db='test')
cur = conn.cursor()
#cur.execute('create table performance(id int not null auto_increment primary key,cpuUsage int,memoryUsage i
nt,physicalUsage int,coreUsage int)') cur.execute("insert into performance(cpuUsage,memoryUsage,diskUsage,cacheUsage) values('%d','%d','%d','%d')"
%(cpu,memory,disk,cache)) cur.close()
conn.commit()
conn.close() class MainHandler(tornado.web.RequestHandler):
global cpu,memory,disk,cache
def get(self):
readTxt()
saveInSql()
self.render('example.html',title='Tornado get&post',x1=cpu,x2=memory,x3=disk,x4=cache) if __name__=='__main__':
tornado.options.parse_command_line()
application = tornado.web.Application([(r'/',MainHandler),],debug=True)
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
python 第一个web程序的更多相关文章
- python第一个web程序
例一: import web urls= ('/(.*)','index') app= web.application(urls,globals()) class index: def GET(sel ...
- 使用MyEclipse开发第一个Web程序
MyEclipse环境配置 首先,安装一个MyEclipse,然后进行一些相关的环境配置(Window->Preferences): 比如字体.Formatter等. 也可以从Eclipse中导 ...
- 【LINUX】——linux如何使用Python创建一个web服务
问:linux如何使用Python创建一个web服务? 答:一句话,Python! 一句代码: /usr/local/bin/python -m SimpleHTTPServer 8686 > ...
- Servlet+JSP教程之:第一个Web程序
我们知道当浏览器发送请求给服务器后,服务器会调用并执行对应的逻辑代码进行请求处理.逻辑代 码是由程序员自己编写然后放进服务器进行运行,其实就是Servlet程序. 第一个Web程序: 开发工具: My ...
- Servlet+JSP(三):第一个Web程序
Servlet+JSP(三):第一个Web程序在学习了服务器并成功安装后,我们知道当浏览器发送请求给服务器后,服务器会调用并执行对应的逻辑代码进行请求处理.逻辑代 码是由程序员自己编写然后放进服务器进 ...
- Django的第一个web程序及深入学习
本学习历程参照Practical Django Projects和http://djangobook.py3k.cn上翻译的内容进行 注:本例以本机加以说明: 根据Django的安装过程可知:在命令行 ...
- [Ruby on Rails系列]3、初试Rails:使用Rails开发第一个Web程序
本系列前两部分已经介绍了如何配置Ruby on Rails开发环境,现在终于进入正题啦! Part1.开发前的准备 本次的主要任务是开发第一个Rails程序.需要特别指出的是,本次我选用了一个(Paa ...
- 第一个web程序(web.xml , ServletConfig , ServletContext)
一:第一个jsp程序 1.项目设计结构 2.新建Person.java package com.java.demo; public class Person { public void printSt ...
- Python开发一个WEB聊天室
项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个群有管理员可以审批用户的加群请求,群管理员可以用多个,群管理员可以删除.添加. ...
随机推荐
- gluPerspective(解释得很好)
http://www.cppblog.com/COOOOOOOOL/archive/2009/12/28/104255.html 函数原型gluPerspective(GLdouble fovy,GL ...
- c中结构体的4种定义
1.常规的标准方式: 1 #include <stdio.h> 2 3 struct student{ 4 int age; 5 float score; 6 ...
- 转: 嵌入式linux下usb驱动开发方法--看完少走弯路【转】
转自:http://blog.csdn.net/jimmy_1986/article/details/5838297 嵌入式linux下的usb属于所有驱动中相当复杂的一个子系统,要想将她彻底征服,至 ...
- Less的用法
Less常用来写样式,比较多的用法是使用第三方软件编译成CSS文件,然后在HTML页面引入CSS文件.而不是直接在HTML页面里引入编译文件和Less文件.如此以来,在后期修改方便的多.当然,在写小项 ...
- 左侧菜单栏右侧内容(改进,有js效果)
(如有错敬请指点,以下是我工作中遇到并且解决的问题)上一篇文章是简洁版 这是上一篇文章的改进. 上一篇文章的左侧菜单是没有子目录的. 这是效果图: 左侧菜单代码: <div class=&quo ...
- 多线程之:竞态条件&临界区
竞态条件指:当一个对象或者一个不同步的共享状态,被两个或者两个以上的线程修改时,对访问顺序敏感,则会产生竞态条件. 临界区指:导致竞态条件发生的代码区. 如:increase块为临界区 public ...
- maven工程开始
clipse中,maven工程,更新pom.xml文件后,会让你更新工程.快捷键是Alt + F5,也可以右键工程,Maven-->update project...,这样有个问题就是默认的JR ...
- api访问参数
一.Get请求 1.一个参数时 2. 二.Post请求
- Python的并发并行[1] -> 线程[1] -> 多线程的建立与使用
多线程的建立与使用 目录 生成线程的三种方法 单线程与多线程对比 守护线程的设置 1 生成线程的三种方法 三种方式分别为: 创建一个Thread实例,传给它一个函数 创建一个Thread实例,传给它一 ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- Red Rover
链接:https://www.nowcoder.com/acm/contest/116/A来源:牛客网 输入描述: Input consists of a single line containing ...