V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
no13bus
V2EX  ›  Python

问个 tornado self.render 的问题。render 能否像 flask 的 return render_template() 那样直接返回,后面不执行了

  •  
  •   no13bus ·
    no13bus · 2015-03-25 15:01:18 +08:00 · 3457 次点击
    这是一个创建于 3318 天前的主题,其中的信息可能已经有所发展或是发生改变。
    代码如下:


    像flask的return render_template() 那样的话, 我就能少写个else了

    刚试了下,貌似这样可以:

    raise gen.Return(self.render("show.html", stars_url=stars_url, cities_url=cities_url, follows_url=follows_url))

    大家都是咋写的呢
    1 条回复    2015-03-25 15:32:25 +08:00
    kxxoling
        1
    kxxoling  
       2015-03-25 15:32:25 +08:00   ❤️ 1
    定义一个继承 BaseHandler 的 Handler,在其中重写 get 方法,这样的话每个 HTTP 方法都需要重写一遍(用不着的话也可以不重写其它方法);
    或者写一个 render 返回值的装饰器,这样用起来会更简单;
    如果你只是想少写一个 else 的话,在第一个 render 后面接上 return 就行了,强制方法结束。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4789 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 05:36 · PVG 13:36 · LAX 22:36 · JFK 01:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.