推荐学习书目
› 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
dodogod
V2EX  ›  Python

有熟悉pylons的吗,tmpl_context对象在页面跳转时能保存上个action里面的数据吗?

  •  
  •   dodogod · Aug 15, 2012 · 4154 views
    This topic created in 5173 days ago, the information mentioned may be changed or developed.
    我想在跳转后的页面上显示错误信息,我记得以前的pylons版本是可以保留数据的,不知道是不是没有配置正确。
    举个例子,代码是这样的
    from pylons import tmpl_context as c
    from pylons.controllers.util import redirect
    class TestController(BaseController):
    def test1(self):
    c.message="error message"
    redirect("/test/test2")

    def test2(self):
    return c.message
    访问test1,跳转到test2页面就出错了,提示'ContextObj' object has no attribute 'message'。
    3 replies  •  1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
    PRO
       Aug 15, 2012   ❤️ 1
    跳转前设定 message,然后在跳转后显示,这样的 message 通常应该是存在 session storage 里的。
    Js
        2
    Js  
       Aug 15, 2012   ❤️ 1
    用flash或者session

    tmpl_context只是当前请求拿来放模板变量的容器
    dodogod
        3
    dodogod  
    OP
       Aug 15, 2012
    flash是用session实现的吧?
    谢谢楼上
    之前应该是用session,我记错了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:57 · PVG 04:57 · LAX 13:57 · JFK 16:57
    ♥ Do have faith in what you're doing.