一:tornado路由系统:

1、面向资源编程:

场景:当我们给别人提供api的时候,往往提供url。比如:电影票api:

 http://movie.jd.com/book_ticket:预订电影票。
http://movie.jd.com/get_ticket:获取电影票。
http://movie.jd.com/del_ticket:退电影票。

如果我们给别人提供如上url api的话,那么我们和使用接口方的人需要维护这几个url。相应的成本较高。

因为如上的原因,有人根据url(统一资源定位符)提出设想:

我们是否可以根据用户的请求的method来给用户不同的服务呢?

for example:

 def get(*arg):
pass #查询电影票
def post(*arg):
passs #订购电影票
def put(*arg):
pass#退电影票。

根据方法的不同,处理不同的功能。这种提供api方式我们叫做面向资源编程。也叫做restulful(Representational State Transfer缩写,表现层状态转化:http://www.ruanyifeng.com/blog/2011/09/restful)

tornado 天生支持restulful。根据用户的请求的不同,触发不同的函数。以后再给别人提供接口或者在使用别人的接口的时候,需要使用这种面向资源的方式。

2、2级域名,tornado在url划分的时候,比django更加友好,django是在主域名后面接着2级域名比如:http://www.liumeide.com:8888/cmdb/index 配置使用include 进行业务分类url。

而tornado直接使用二级域名来区分不同的业务:http://cmd.liumeide.com:8888/index cmdb服务,http://www.liumeide.com:8888/index  主站服务。http://monitor.liumeide.com:8888/index  监控服务。

京东也是这么区分,只不过京东各个系统是相对独立的。

主站:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAakAAACOCAIAAAAEkGA2AAAUKElEQVR4nO2dT2gbVx7H5cYsvYQQKA3GOcXH9m7QIVDwaXFyc2N6zMEL9iWH7ELBB7f4LHpICCkEb/CflkAhqbf2CqUJ65DGNSxBcslhtU1YCjZO7F1bVVNpFM3bw0/++fm9N2/ejGWP4vl++RCkkUZy5vDh997vzVNmfacBAABpI3PvH08BACBtZN4gCIKkLxmBIAiSvsB9CIKkMZHd99NPPx3G34EgCHKUyaytrT18+PDOnTt37tx5+PDh+vq67/uWE+A+BEGOQTKPHj16+fJlrVar1WovX75cWlqamZn59ddfg06A+xAEOQYxjHlfvXo1PT29s7NjPOEo3VculzOZTLlcVo4vLCxks9kj+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dTzymUIkKGCBk/99eVaNobw0o0Rj9kGSGx6WCuYWuLd9K/+kv19LaMKfUNQDsDbC0zP3Wpi0vHTrwdf5i5Z+f85Az13B5bdY3/amN8IefX6tPcdeeGd+zMOFwWX1gwv35c9fwL9Ifo0q6KREZfetW4/5Dz41PB+w+4N/5QTekPvOiBu4UAAAGCSURBVEztrlyyp309v/PjU9rtZcbKXxvK9+u279U/+0LBKX3eUPaiseKgrnSv+fBR5jtEWCq3nHyPY/piTq6wnHwv15vWgk6vLtoxdvSE5/xXhf5WAVZoZ4AtZWV5JvRojuWAW4L+EHY0czKBQ3wxshycWVlZO+a2Eo0uB2cSj1j+338lHo8vLKzk/YnwRCKxHJzJmJiOzy8sB2cezYY3n+XQ7KPwXIIx+Fz78pmPOsdqK48ecfymmA1AOwMA8BHaGQCAj9DOAAB8hHYGAOAjtDMAAB+hnQEA+AjtDADAR2hnAAA+QjsDAPAR2hkAgI/QzgAAfIR2BgDgI7QzAAAfoZ0BAPgI7QwAwEdoZwAAPkI7AwDwEdoZAICP0M4AAHyEdgYA4CO0MwAAH6GdAQD4CO0MAMBHaGcAAD5COwMA8BHaGQCAj9DOAAB8hHYGAOAjtDMAAB+hnQEA+AjtDADAR2hnAAA+QjsDAPAR2hkAgI/QzgAAfIR2BgDgI7QzAAAf/X9zGwEaqI90HgAAAABJRU5ErkJggg==" alt="" />

配置:

 application.add_handlers("cmd.liumeide.com",#重新设置url使用add_handlers方法,第一个参数是2级域名名称,后面是url列表。
[
(r"/index", CmdbHandler)
]

完整代码:

 #!/usr/bin/env python
# -*- coding:utf- -*- import tornado.ioloop
import tornado.web class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("mian web")
class CmdbHandler(tornado.web.RequestHandler):
def get(self):
# self.write("Hello, world")
self.write('cmdb')
setting={
'template_path':'template',#设置模板文件路径。
'static_path':'static'#设置静态资源路径
}
application = tornado.web.Application([
(r"/index", MainHandler),
],**setting)
application.add_handlers("cmd.liumeide.com",#重新设置url使用add_handlers方法,第一个参数是2级域名名称,后面是url列表。
[
(r"/index", CmdbHandler)
]
) if __name__ == "__main__":
application.listen()
tornado.ioloop.IOLoop.instance().start()

note:

  1. 他们公用一个setting配置。!!!

效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAScAAABXCAIAAADJbRRjAAAMeklEQVR4nO2d+W/b5h2H+fcMw7BhA4a66IEO3bphWNMzPdY2h+s0aXN0SYO0SRq3wJAVBTqh6xGnVRLHSuPIiW1ZsZJYvmLLMn3LlmzrPihK1EVJPiVRgbUfGDOvSIqiY5mxne+Dzw/Uy/elKFKP+b4vaRuLzuchEIiSwSLzeQgEomTAOghE6WCRubz8hFM5b2Rhxh+fdFPjjvCYPTRmD407wpNuasYf90YWqDSzpg1CII9hMGouLycEnZkJJEZmSYubcpIpf2wxSGeodC6cygbpjD+26CRTFjc1MkvOBBLBZFbmZiGQxzDlrQunGXswOWonZwJ0OJWTvnSGU7lZgh61kw4yFU4zj/zjQSCbMGWsI+jshJua9sXDqaz8bms4lZ32xSfcFEFnHvknhEA2W7DwXL5UAonlUUfYEUpR8/mHiJ1M6e9O/nzdeKG5u+I5d61Dd3cCAtmKwcLpvGgC8czwDOmm5tbjtIeaH5klSTobnb9X2dRpO+4BwNZE3DoyyYzaw/Zgav0XU3swNeYIU2mm4tYVAGBrgoXSeWFs/sSkJ1qpXqzFHZkJJCLz9yoYsA7YuohY549nhqaDQXkTIfiUe9jmla4TpO9vcDNbZ7PZKrtBACgFRqbzvEz5EjaClphl4WIctPz8i+6nK639Y3bpmjaCtvkT1Pw96Rh6h7/96UowmS1b85ykdSsrK+FwuKenR6vVarXanp4eiqJWVlYkmoB1gGJgZCqPhqBz+HSQTOZKzbJwMZotl661N7Z1X9V1XbiqD6UYicpkModPB0Mphpq7Vyo9uPV3Tzz32yeeq/7oOJnMSdSk5u6du1bSuvn5+YaGhv7+/lgsls1ms9lsLBbr6+vTaDQLCwulWoF1gGJgZIpB4wjNjTmpcJqRjtFsuaRtv3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TAHeAYiWmfdR2N6pa9Ov3Nzd3wzs9uhIHen2gVLDaZ/PdmHVnU75lqZ7BxTGXAoIzHlttZiVXs7p93sYXa4VdNNEduZemeIbFzpR624OECBmEctrBddGBbNCm0Z4quoM/QCs8WMELGYAtbrWvucDdbvtoh2iy0G1aRksVcF/28BbKAgRnXs4V9KzWgLdrsXmsiWoXugo7OCflWLmbvGIaBYRjPvIWaS5C5+cC26F7E6Quo0u43Crcb7//tDgD9+c6/ywdghMAWAHiBLQDwAlsA4AW2AMALbAGAF9gCAC+wBQBeYAsAvMAWAHiBLQDwAlsA4AW2AMALbAGAF9gCAC+wBQBeYAsAvMAWAHiBLQDwAlsA4AW2AMALbAGAF9gCAC+wBQBeYAsAvMAWAHiBLQDwAlsA4AW2AMALbAGAF9gCAC+wBQBeYAsAvMAWAHiBLQDwAlsA4AW2AMALbAGAF9gCAC+wBQBeYAsAvMAWAHiBLQDw8n+T7CfaCSbr+wAAAABJRU5ErkJggg==" alt="" />

二:模板语言:

在模板语言中,for循环支持break、continue等语法,语法形式:{%break%} 也支持python的一些方法.比如lenth等。

也支持母板和子板,只是结束符是end 而不是 endblock。

 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>老男孩</title>
<link href="{{static_url("css/common.css")}}" rel="stylesheet" />
{% block CSS %}{% end %}
</head>
<body> <div class="pg-header"> </div> {% block RenderBody %}{% end %} <script src="{{static_url("js/jquery-1.8..min.js")}}"></script> {% block JavaScript %}{% end %}
</body>
</html>

子板:

 {% extends 'layout.html'%}
{% block CSS %}
<link href="{{static_url("css/index.css")}}" rel="stylesheet" />
{% end %} {% block RenderBody %}
<h1>Index</h1> <ul>
{% for item in li %}
<li>{{item}}</li>
{% end %}
</ul> {% end %} {% block JavaScript %} {% end %}

导入:也有页面的导入

header.html

 <div>
<ul>
<li></li>
<li>42区</li>
</ul>
</div> header.html
 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>老男孩</title>
<link href="{{static_url("css/common.css")}}" rel="stylesheet" />
</head>
<body> <div class="pg-header">
{% include 'header.html' %}
</div> <script src="{{static_url("js/jquery-1.8..min.js")}}"></script> </body>
</html> index.html

自定制功能:uimethod和uimodlues。

对比:

  • 2者都可以给前端传递参数,不过method只能传递方法函数,而uimodules传递是类,通过类定义不同的方法,前端调用不方法函数。
  • uimodules可以给前端传递js、css等。

uimethod:

首先需要定义个模块比如:co.py. 然后写方法:

 def f1(self,a):
return a

在配置setting中注册:

 import  co
setting={
'template_path':'template',#设置模板文件路径。
'static_path':'static',#设置静态资源路径
'ui_methods':co,#注册
}

后台代码:

 #!/usr/bin/env python
# -*- coding:utf- -*- import tornado.ioloop
import tornado.web
import co class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('main.html')
setting={
'template_path':'template',#设置模板文件路径。
'static_path':'static',#设置静态资源路径
'ui_methods':co,
}
application = tornado.web.Application([
(r"/index", MainHandler),
],**setting) if __name__ == "__main__":
application.listen()
tornado.ioloop.IOLoop.instance().start()

前端页面引用:注意是2个大括号类似于变量的引用。

 <h1> {{f1()}}</h1>

效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAABqCAIAAACTVRtpAAAKXUlEQVR4nO2c217aSh+Gc11ekNfhJXhq10eXLumqxbpBKm3FvQhxj4oIsoeQsAvgFhJa+Q5mrawxCSGIU62+z+89iJNMOiQ85D+DlitdtREEYRSueNVGEIRRIBiCMAxXvGzbj1hXUsXrSKZynJAOY+JBtHAQLRzGxOOEFMlUUsVrqaH2dUIEed3hpMu2neTkZiRb3TsXQgnpQqhnyjd5uSk1FLHeysvNTPnmQqiHEtLeuRDJVvO1ls3TIsjrTm/BxIYazdf2o0IkK4t1xfqBKNaV85y8HxViQl1sqM/+8hDkedNDsJzcOkpIZ+mKWG/ZrzvFeussXTlKSDm5+eyvEEGeMZx42e6WbPVuPybGCnXpqv2IRIX6UjAys7Ln3jhCkLcZTmy0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dFU1JpSs7sdKuumZaXI1NdfrmL1oUcAfXII3iblgqYoSjIjHadmOY9Y5TsuRTMm60gPgtcKlqqpp4qXm1mn+TLg0TtLsJ5xrHESF9o+nLw4B+C3gUlWlW6LS9eZJNpSWM7LyiBylqh++7jjmNya+bCPI24yVYKmqEpNu/af53VgxUbq1r1aidLsTlfyn+WTZzkoJgrzacMmKYp1EubUfL68dpQ/i5XjxLl1VLBIv3u5flNeO0geJcqLc6nlyBHnd6S0YSUy6270orYcy22fCYVI+L1wlSnepSitVaV0Ub88L14dJeftMWA9ldi9KMenu2V8YgryE2BWMJF5qnmTrO7GSPyyshzKrh6nVw9R6KOMPCzux0km2Hi81n/0lIcjLCZeoKAiCMAqXKCsIgjAKFy8rCIIwCgRDEIbhXMtHCIIwyq/+f8gAeFNAMAAYAsEAYAgEA4AhEAwAhkAwABgCwQBgCAQDgCEQDACGQDAAGALBAGAIBAOAIRAMAIZAMAAYAsEAYAgEA4AhEAwAhkAwABgCwQBgCAQDgCEQDACGQDAAGALBAGAIBAOAIRAMAIZAMAAYAsEAYAgEA4AhEAwAhtgWLD46xOkZ9rIcGgC/PzYEM1OLYmg0zn6YAPye9BKsh11wDAArrAWzpRcUA6AbloLp/aLmXPpdMAwAE6wEeyiRQSHvcBf5AAD/YCXYA4NMHlG99gPw5hnke7AHguEJBoCRAQTDAwyAXjxasB4TNABA59GCPVzgQH0IgDmPEUxnF/QCoBv9Cmb46hnFIQDd6Usw2AVAf9gXTF8YojIEoCc2BdPbhUcXAHawI5jOLsgFgF16Cqabd8EuAPqgh2A6vTDtAqAv+vpzFSvwaAPAiP0/V4FgAPSNhWB9+QXBADChu2D9+QXBADAB/y8iAAyBYAAwBIIBwBAIBgBDIBgADIFgADAEggHAEAgGAEMgGAAMgWAAMASCAcAQCAYAQyAYAAyBYAAw5P8t6WFnCTMIiQAAAABJRU5ErkJggg==" alt="" />

uimodles:

1、定义模块文件:oc.py

2:写类和方法。

 #!/usr/bin/env python
# -*- coding:utf- -*-
from tornado.web import UIModule
from tornado import escape class custom(UIModule):#注意需要继承模块。 def render(self, *args, **kwargs):
return '<h1> 2</h1>'
def javascript_files(self):
return 'http://111.js'
def css_files(self):
return 'http://222.css'

3:前端注册

 #!/usr/bin/env python
# -*- coding:utf- -*- import tornado.ioloop
import tornado.web
import co
import oc
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('main.html')
setting={
'template_path':'template',#设置模板文件路径。
'static_path':'static',#设置静态资源路径
'ui_methods':co,
'ui_modules':oc,
}
application = tornado.web.Application([
(r"/index", MainHandler),
],**setting) if __name__ == "__main__":
application.listen()
tornado.ioloop.IOLoop.instance().start()

4:页面引用:

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1> {{f1(2)}}</h1>
{% module custom(22) %}<!--注意页面的引用方式不一样uimodule是需要关键字module 以及百分号和uimethod的不同-->
</body>
</html>

效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR0AAACzCAIAAAA7aV8GAAALZklEQVR4nO3d617a2BqA8VyXF+R1eAl+dfZ2po506uDUilTaiqdWRDy0RcUjRznKIahtVcAZ2R+yJy6SEAIsq63P//d+wECYCD6ygtpR8hc37eakcrV1lD/KnRW+3PQwh9mzubX9lwubnvefGeZJjZI/v7Gck/L1xn42VrgoXNz0PPHCl/BR9uq69jfwlFh3la02tg7zh5mzfqLS5jBztp8o/PPPP03gyVBy5zfmiaQq2/Fi/1FpE46d5opnD/2ZAt+PRVep8vX6XiajXjtpJrQT24gk7G+TUa83DzK1+o30o49EItLvE+ifkj2/McxOshJJqzbvZ+jjXwv/9w/Pf55Pr3w8tL9lJK0mC1X7Q7m9vc3n80tLS2632+12Ly0tFQqF29tbm13oCo+Tkj27ESet1kN7mWy13u79DH38wfCzP2cnZhZfeBZ+feHNnTVsbpyt1jcOMjZnWV++fBkfH19ZWSmVSrVarVarlUqlDx8+uFyur1+/ttuLrvA4KdmzhjhHuYuPx4X8ecN+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NDBqKzu2UuN6N+2Y7BghNNhqfey48rD+zs9+ZZVJsOO/frev/8xqxx9+PMHYMUJosNX6mxXetyxCdqyf75mP8uqOHZsP/fTQM29WIIROg1p879ibGiOEEGpZ/CoPIYSiEHaMEEJRCDtGCKEoxPTzAABRgB0DAEQBdgwAEAXYMQBAFPw/MNRhWWiRhvAAAAAASUVORK5CYII=" alt="" />

三:tornado session

设计思想:

  • 服务器端产生随机字符串并写入客户端,下次客户端请求的时候携带这个随机字符串。
  • 服务器端需要储存该随机字符串,并额外保存用户其他信息,比如:用户名。
  • 客户端每次请求,需要判断客户端是否有已经写入cookie。
  • 每次访问,更新cookie过期时间。而不是每次都写入随机字符串。
  • session信息可以存储在内存、数据库、redis等。设置过期时间,定期清理,释放磁盘空间。
  • 对于伪造的cookie,重新写入客户端。
  • 随机字符串可以用time来生成md5写入客户端。

代码实现:

 #!/usr/bin/env python
#-*-coding:utf--*-
# author:liumeide
import hashlib
import time
Session_Info={} def md5():
m = hashlib.md5()
m.update(bytes(str(time.time()),encoding='utf-8'))
return m.hexdigest() class Session:
def __init__(self,handler):
self.handler=handler
def check_se(self):
current_time = time.time()
ret = self.handler.get_cookie('cookie_str', None) # 自定义cookie key值。下次访问的请求的时候根据这个key来获取cookie的随机字符串。
if ret: # 在有效的cookie设置范围内。
if ret in Session_Info.keys(): # 合法的cookie
cookie_str = ret
return True
else: # 非法伪造或者过期的cookie。
cookie_str = md5()
else: # 第一次访问请求设置cookie
cookie_str = md5()
Session_Info[cookie_str] = {}
self.handler('cookie_str', cookie_str, expires=current_time + ) # 无论你是第一次还是多次请求,cookie都需要重新写入浏览器。需要设置过期时间。 def __getitem__(self, item):#获取cookie
pass
def __setitem__(self, key, value):#设置cookie
pass
def __delitem__(self, key):#删除ookie
pass

tornado 路由、模板语言、session的更多相关文章

  1. 第二百五十九节,Tornado框架-模板语言的三种方式

    Tornado框架-模板语言的三种方式 模板语言就是可以在html页面,接收逻辑处理的self.render()方法传输的变量,将数据渲染到对应的地方 一.接收值渲染 {{...}}接收self.re ...

  2. flask 基本操作 模板语言 session

    Django web:优点:大而全,ORM models ,model Form ,admin ,csrf ,session缺点:资源浪费 Flask web:优点:小而精,ORM:x , Form: ...

  3. web框架详解之tornado 一 模板语言以及框架本质

    一.概要 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过 ...

  4. tornado框架&三层架构&MVC&MTV&模板语言&cookie&session

    web框架的本质其实就是socket服务端再加上业务逻辑处理, 比如像是Tornado这样的框架. 有一些框架则只包含业务逻辑处理, 例如Django, bottle, flask这些框架, 它们的使 ...

  5. flask之web网关、三件套、配置、路由(参数、转化器及自定义转化器)、cbv、模板语言、session

    目录 1.wsgiref.py 2.werzeug.py 3.三件套 4.配置文件 5.路由本质 6.cbv.py 7.路由转化器 8.自定义转化器 9.模板语言 10.session原理 11.te ...

  6. [Python自学] Flask框架 (1) (Flask介绍、配置、Session、路由、请求和响应、Jinjia2模板语言、视图装饰器)

    oldboy:s9day114 参考博客:https://www.cnblogs.com/wupeiqi/articles/7552008.html 一.Flask简介 1.安装Flask pip i ...

  7. python 全栈开发,Day119(Flask初识,Render Redirect HttpResponse,request,模板语言 Jinja2,用户登录例子,内置Session)

    一.Flask初识 首先,要看你学没学过Django 如果学过Django 的同学,请从头看到尾,如果没有学过Django的同学,并且不想学习Django的同学,轻饶过第一部分 三大主流Web框架对比 ...

  8. url路由、模板语言、ajax、用django框架创建表

    1.后台管理的左侧菜单,默认只有第一个页签下面的选项是显示的,点了别的页签再显示别的页签下面的选项,问题是:点了任何菜单的选项后,左侧菜单又成了第一个页签的选项显示,别的页签隐藏,也就是左侧的菜单刷新 ...

  9. 第二百五十八节,Tornado框架-逻辑处理get()方法和post()方法,初识模板语言

    Tornado框架-逻辑处理get()方法和post()方法,初识模板语言 Tornado框架,逻辑处理里的get()方法,和post()方法 get()方法,处理get方式的请求post()方法,处 ...

随机推荐

  1. linux 软件包 rpm命令之安装、更新、卸载、依赖

    软件包分类1.源码包2.二进制包二进制包是源码包编译后产生的文件..exe文件是适用于windows平台的二进制包:RPM包适用于redhat系列的二进制包:deb包是适用于ubuntu平台的二进制包 ...

  2. Centos7安装最新版本的docker

    centos7 安装docker-ce ,最新版本docker,docker阿里云加速docker-ce是指docker的社区版 卸载老版本的 docker 及其相关依赖sudo yum remove ...

  3. HTML5-入门3。

    CSS选择器. 什么是标签选择器?作用: 根据指定的标签名称, 在当前界面中找到所有该名称的标签, 然后设置属性 格式: 标签名称{ 属性:属性值 } 标签选择器(html中的标签名称) id选择器( ...

  4. commonjs详解

    marked here a well written artical http://javascript.ruanyifeng.com/nodejs/module.html

  5. python下载指定的版本包

    首先我们很多时候在执行pip的时候是不行的  有时候很难成功,这个时候我们就要想其他的版本了 一.是不是这个包需要指定版本, 比如python2的和mysql链接的是,而python3则是mysqlc ...

  6. 辉光UIView的category

    辉光UIView的category 本人视频教程系类   iOS中CALayer的使用 效果如下: 源码: UIView+GlowView.h 与 UIView+GlowView.m // // UI ...

  7. redis几种数据类型以及使用场景

    1. string类型 string为最简单类型,一个key对应一个value set mykey "wangzai" ##设置key,第二次赋值会直接覆盖之前的 setnx my ...

  8. gradle结合spring-boot生成可运行jar包,并打印日志

    1.用gradle把springboot项目打包成jar 1.1 build.gradle 中添加 buildscript { repositories { mavenLocal() maven { ...

  9. [2018HN省队集训D1T3] Or

    [2018HN省队集训D1T3] Or 题意 给定 \(n\) 和 \(k\), 求长度为 \(n\) 的满足下列条件的数列的数量模 \(998244353\) 的值: 所有值在 \([1,2^k)\ ...

  10. if 的一切

    第一种语法: if 条件: # @引号是为了把条件和结果分开. 结果1 # 一个Tab或者4个空格 @告诉程序满足上面的if条件才会执行结果1结果2 如果条件为真(True),执行结果1,然后执行结果 ...