当前位置: 编程技术>软件工程/软件设计
本页文章导读:
▪Tornado的初步了解
今天看了下Python的一个新web框架,由Facebook开源。不得不说,品牌效应啊,只要是Facebook开源的项目,没有不好用的。Tornado可以说是好用到了极致,从打开官方页面开始.........
▪二级导航栏 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="三层复习2013_04_22.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
.........
▪Nginx屏蔽F5心跳日志 location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mmt;
if ( $remote_addr != 192.168.0.2 ) {
access_log /var/log.........
[1]Tornado的初步了解
来源: 互联网 发布时间: 2013-11-19
今天看了下Python的一个新web框架,由Facebook开源。不得不说,品牌效应啊,只要是Facebook开源的项目,没有不好用的。Tornado可以说是好用到了极致,从打开官方页面开始了解,到搭建一个web服务器,只用了10分钟。
另外,Tornado支持websocket通讯,和前几天看的通过Netty支持Websocket相比,Tornado的操作要显得简单得更多。
下载地址:http://www.tornadoweb.org/en/stable/
安装步骤:
tar xvzf tornado-3.0.1.tar.gz cd tornado-3.0.1 python setup.py build sudo python setup.py install
服务器代码如下:
import tornado.ioloop
import tornado.web
import tornado.websocket
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class MainHandler2(tornado.web.RequestHandler):
def get(self):
self.write("This is a test")
class EchoWebSocket(tornado.websocket.WebSocketHandler):
def open(self):
print "WebSocket opened"
def on_message(self, message):
self.write_message(u"You said: " + message)
def on_close(self):
print "WebSocket closed"
application = tornado.web.Application([
(r"/", MainHandler),
(r"/test", MainHandler2),
(r"/websocket", EchoWebSocket),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
只需要在application中注册url对应的handler即可,对于websocket,只要让handler继承自tornado.websocket.WebSocketHandler。
然后用以下代码测试:
<html><head><title>Web Socket Client</title></head>
<body>
<script type="text/javascript">
var socket;
if (!window.WebSocket) {
window.WebSocket = window.MozWebSocket;
}
// Javascript Websocket Client
if (window.WebSocket) {
socket = new WebSocket("ws://localhost:8888/websocket");
socket.onmessage = function(event) {
var ta = document.getElementById('responseText');
ta.value = ta.value + '\n' + event.data
};
socket.onopen = function(event) {
var ta = document.getElementById('responseText');
ta.value = "Web Socket opened!";
};
socket.onclose = function(event) {
var ta = document.getElementById('responseText');
ta.value = ta.value + "Web Socket closed";
};
} else {
alert("Your browser does not support Web Socket.");
}
// Send Websocket data
function send(message) {
if (!window.WebSocket) { return; }
if (socket.readyState == WebSocket.OPEN) {
socket.send(message);
} else {
alert("The socket is not open.");
}
}
</script>
<h3>Send :</h3>
<form onsubmit="return false;">
<input type="text" name="message" value="Hello World!"/><input type="button" value="Send Web Socket Data" onclick="send(this.form.message.value)" />
<h3>Receive :</h3>
<textarea id="responseText" style="width:500px;height:300px;"></textarea>
</form>
</body>
</html> 效果如下:
作者:lrenjundk 发表于2013-5-7 17:24:56 原文链接
阅读:73 评论:0 查看评论
[2]二级导航栏
来源: 互联网 发布时间: 2013-11-19
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="三层复习2013_04_22.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
#ceng {
float:right;
display:none;
width:150px;
margin-top:-39px;
position:absolute;
margin-left:150px;
border-left:1px solid #fff;
background-color:#000;
}
ul {
list-style: none;
width:150px;
text-indent:0px;
background-color:#000;
}
li {
background-color:#943e00;
padding:10px 0 10px 20px;
margin-left:-40px;
cursor:pointer;
border-bottom:1px solid #000;
}
li:hover {
background-color:#aaa;
}
#div2 {
width: 150px;
background-color:#000;
}
</style>
<script src=/blog_article/"Jquery1.7.js"></script>/index.html
<script type="text/javascript">
$(function () {
$('#div2 ul>li').mouseover(function () {
$('#ceng ul').remove();
$('#ceng').css('display', 'block');
var a = '<ul>';
for (var i = 0; i < 5; i++) {
a+='<li>'+$(this).text()+'</li>';
}
$('#ceng').append(a + '</ul>');
//alert($('#ceng').offset('left'));
$(this).after($('#div3'));
$('#ceng').css('float','right');
})
$('#div2 ul>li').mouseout(function () {
$('#ceng').css('display', 'none');
})
$('#ceng').mouseover(function () {
$('#ceng').css('display', 'block');
})
$('#ceng').mouseout(function () {
$('#ceng').css('display', 'none');
})
})
alert(this.document.getElementById('ceng').offsetLeft());
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="div3">
<div id="ceng"></div>
</div>
<div id="div2">
<ul>
<li>
.2.3.4.5..
</li>
<li>
你是我的谁
</li>
<li>
谁是谁的谁
</li>
</ul>
</div>
</form>
</body>
</html>
作者:anxin591025 发表于2013-5-7 19:31:50 原文链接
阅读:0 评论:0 查看评论
[3]Nginx屏蔽F5心跳日志
来源: 互联网 发布时间: 2013-11-19
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mmt;
if ( $remote_addr != 192.168.0.2 ) {
access_log /var/log/nginx/nginx_access_abres.log;
}
}
注:192.168.0.2是F5内网地址。
下面的配置经测试是失败的,依然记录访问日志:
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mmt;
deny 192.168.0.2;
}推测是日志记录在deny前执行,执行到deny返回403Forbidden。
作者:xxd851116 发表于2013-5-7 21:05:12 原文链接
阅读:71 评论:0 查看评论
最新技术文章: