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
dodogod
V2EX  ›  Python

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

  •  
  •   dodogod · 2012-08-15 01:39:18 +08:00 · 3172 次点击
    这是一个创建于 4265 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想在跳转后的页面上显示错误信息,我记得以前的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 条回复    1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
       2012-08-15 04:52:58 +08:00   ❤️ 1
    跳转前设定 message,然后在跳转后显示,这样的 message 通常应该是存在 session storage 里的。
    Js
        2
    Js  
       2012-08-15 09:29:52 +08:00   ❤️ 1
    用flash或者session

    tmpl_context只是当前请求拿来放模板变量的容器
    dodogod
        3
    dodogod  
    OP
       2012-08-15 17:02:13 +08:00
    flash是用session实现的吧?
    谢谢楼上
    之前应该是用session,我记错了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4118 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 10:13 · PVG 18:13 · LAX 03:13 · JFK 06:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.