tornado-输出,request
3种输出方法:write render redirectimport tornado.ioloop
import tornado.web
import tornado.httpserver # 非阻塞
import tornado.options # 提供了多种选择 python xxx.py --port=xxxx
from tornado.options import define,options
define('port',default=8000,help='run port',type=int) # windows通过Ctrl+鼠标左键
define('version',default=0.1,help='version',type=str) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("ces.html") # 写入页面 class RecHandler(tornado.web.RequestHandler):
def get(self):
self.redirect(r"/rec1") # 在进入这个网址(路由),自动跳转到rec1去 class Rec1Handler(tornado.web.RequestHandler):
def get(self):
self.write("由/rec跳转过来") # request
self.write(self.request.remote_ip) # remote_ip属性查询发送请求的ip地址
# (浏览器->virtualBox->虚拟环境 所以得到的不是浏览器的ip)
print(self.request.full_url()) # full_url方法查询完整的url
print(self.request.request_time()) # 处理请求的时间
application = tornado.web.Application(
handlers=[
(r"/",MainHandler),
(r'/rec', RecHandler),
(r'/rec1', Rec1Handler),
],
template_path='templates', # 表明页面html的路径
debug=True # 上传代码后服务器自动重启
) if __name__ == '__main__':
tornado.options.parse_command_line() # 通过sys.arg获取命令行输入参数(python xxx.py --port=xxx)
print(options.port)
print(options.version)
http_server = tornado.httpserver.HTTPServer(application) # 非阻塞
application.listen(options.port)
tornado.ioloop.IOLoop.instance().start() # 启动io循环 # 知识点 # 输出3种: # write 输出到浏览器。 先写入缓冲(flush直接写到浏览器)再一起写入浏览器
write 可写入 三种类型 unicode字符串,dict,和 /b
# render写入页面 html文件
# template_path = 'templates', # 这句写在路由表里,表明路径templates # redirect 自动跳转页面
# 在进入这个网址(路由),自动跳转到另一个网址 # request
#.remote_ip查询发送请求的ip地址 # debug调式 虫子--晶体管
tornado-输出,request的更多相关文章
- Tornado输出和响应头
1.输出 再来看看输出`write`,实际上,`write`并没有直接把数据返回给前端,而是先写到缓存区,函数结束之后才会返回到前端,我们验证如下 class FlushHandler(tornado ...
- tornado输出json
只需要输出一个dict就自动会变成json http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.write
- tornado RequestHandler request.body & request.arguments
request.body , 请求的原始内容,post方式放在body中的. request.arguments, body参数和url参数的统一体, 同时也是经过“加工”,解码的. eg.在对接其他 ...
- 2.tornado请求与响应
之前我们介绍了tornado的基础流程,但还遗留了一些问题.今天我们就来解决遗留问题并学习新的内容 settings,使用tornado.web.Application(handler, **sett ...
- 2.(基础)tornado的请求与响应
之前我们介绍了tornado 的基础流程,但是还遗留了一些问题,今天我们就来解决这些遗留问题并学习新的内容 settings,使用tornado.web.Application(handler, ** ...
- struts2 request内幕 为什么在struts2用EL表达式可以取值
不知道大家有没有想过这样一个问题:为什么在action中的实例变量,没有使用request.setAttribute()方法将值添加到request范围内,却能在jsp中用EL表达式取出? 众所周知, ...
- Strut2 ognl取出存放在request,session,application和对象栈的中的值
1.取出request,session,applicaiton中的值 a.往里面加入request,session,application中加入值 public String testServlet( ...
- Flask的request和session是从哪里来的?
因为之前一直在项目中使用django, 所以在学习Flask的过程中, 难免对吧django和Flask进行对比, 这一次我发现Flask中的request和session并没有想象的那么简单, 所以 ...
- tornado框架基础01-路由简介
tornado 小而精 Django 大而全 Web框架 Tornado是一个由Python开发的Web框架 Web服务 利用Tornado,可以快速搭建和一个高性能的Web服务 非阻塞 Tornad ...
- <c:out>标签不能正确输出value中的值
问题: 我打算在jsp中输出request中的值,它的key为username, <c:out value="${requestScope.username}"/> 但 ...
随机推荐
- android中的5大布局
1.线性布局:LinearLayout layout_margin 上下左右的距离分别为 下面图中的orientation表示的是布局中的方向 分别有horizontal表示水平 vertic ...
- BZOJ1071: [SCOI2007]组队【双指针】【思维好题】
Description NBA每年都有球员选秀环节.通常用速度和身高两项数据来衡量一个篮球运动员的基本素质.假如一支球队里速度最慢的球员速度为minV,身高最矮的球员高度为minH,那么这支球队的所有 ...
- C++ 拷贝构造函数和赋值构造函数
转自:http://blog.chinaunix.net/uid-28662931-id-3496326.html 一.拷贝构造函数 int main(int argc, char * argv[]) ...
- L3-020 至多删三个字符 (30 分)
给定一个全部由小写英文字母组成的字符串,允许你至多删掉其中 3 个字符,结果可能有多少种不同的字符串? 输入格式: 输入在一行中给出全部由小写英文字母组成的.长度在区间 [4, 1] 内的字符串. 输 ...
- hdu1166 敌兵布阵 树状数组/线段树
数列的单点修改.区间求和 树状数组或线段树入门题 #include<stdio.h> #include<string.h> ],N; void add(int x,int a) ...
- 原子性、可见性、synchronized 有好理解
原子性.可见性.synchronized 有好理解: from: https://blog.csdn.net/wohaqiyi/article/details/67635010 1.原子性 (1)原子 ...
- Microsoft - Find the K closest points to the origin in a 2D plane
Find the K closest points to the origin in a 2D plane, given an array containing N points. 用 max hea ...
- Java JDK 版本的区别
jdk6和jdk5相比的新特性有: 1.instrumentation 在 Java SE 6 里面,instrumentation 包被赋予了更强大的功能:启动后的 instrument.本地代码 ...
- 【转】每天一个linux命令(21):find命令之xargs
原文网址:http://www.cnblogs.com/peida/archive/2012/11/15/2770888.html 在使用 find命令的-exec选项处理匹配到的文件时, find命 ...
- SQL语言:DDL/DML/DQL/DCL
SQL (Structure Query Language)语言是数据库的核心语言. SQL 的发展是从1974年开始的,其发展过程如下: 1974年-----由Boyce和Chamberlin提出, ...