geew
V2EX  ›  问与答

[Tornado Template] 如何在模板里面返回当前的request对象呢?

  •  
  •   geew · Dec 6, 2013 · 2596 views
    This topic created in 4725 days ago, the information mentioned may be changed or developed.
    比如self.current_user, 难道要每次把user传过去么??
    flask有g.user可以直接使用, 貌似tornado没有类似的东西吧.
    4 replies  •  1970-01-01 08:00:00 +08:00
    9hills
    9hills
    Dec 6, 2013
    1
    有的,不过tornado的文档太简略没写

    http://www.tornadoweb.org/en/stable/_modules/tornado/web.html#RequestHandler.get_template_namespace

    这里有默认的template namespace,其中你看到有request吧

    那么直接在template里 {{request.xxx}}就能访问request的成员了
    9hills
    9hills
    Dec 6, 2013❤️1
    2
    另外你可以override这个方法,增加属于自己的namespace<_<
    geew
    geew
    OP
    Dec 6, 2013
    3
    @9hills 谢谢
    geew
    geew
    OP
    Dec 11, 2013
    4
    @geew 自定义添加自己的 @geew 命名空间确实好用啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4427 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 07:48 · PVG 15:48 · LAX 23:48 · JFK 02:48
    ♥ Do have faith in what you're doing.