推荐学习书目
› 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 · Mar 25, 2015 · 4392 views
    This topic created in 4204 days ago, the information mentioned may be changed or developed.
    代码如下:


    像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 replies  •  2015-03-25 15:32:25 +08:00
    kxxoling
        1
    kxxoling  
       Mar 25, 2015   ❤️ 1
    定义一个继承 BaseHandler 的 Handler,在其中重写 get 方法,这样的话每个 HTTP 方法都需要重写一遍(用不着的话也可以不重写其它方法);
    或者写一个 render 返回值的装饰器,这样用起来会更简单;
    如果你只是想少写一个 else 的话,在第一个 render 后面接上 return 就行了,强制方法结束。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1134 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:13 · PVG 01:13 · LAX 10:13 · JFK 13:13
    ♥ Do have faith in what you're doing.