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

Flask 中的 Session 和 SessionInterface 的问题

  •  
  •   shinerene ·
    Xiechen · Jun 1, 2014 · 5167 views
    This topic created in 4390 days ago, the information mentioned may be changed or developed.
    对于Flask中的Session和SessionInterface该如何使用?有没有可以提供一点实例代码?
    比如说初始化session 和sessioninterface的open_session和save_session该怎么样使用?
    有没有实例代码?
    7 replies    2014-06-03 09:39:01 +08:00
    wuxqing
        1
    wuxqing  
       Jun 1, 2014
    shinerene
        2
    shinerene  
    OP
       Jun 1, 2014
    恩 我知道这个 但是应该怎么在主代码中使用这个interface和session呢?能说一下实际该怎么应用么
    dagger
        3
    dagger  
       Jun 1, 2014
    初始化之后不用再管SessionInterface了吧,session使用的话,教程里就有啊
    http://flask.pocoo.org/docs/quickstart/#sessions
    shinerene
        4
    shinerene  
    OP
       Jun 1, 2014
    @dagger 可是我用help()看了session,Session是不一样的,Session是SecureCookieSession类,而session是定义在global类中的,为localproxy()。这两个我在应用的时候应该用Session吧
    dagger
        5
    dagger  
       Jun 2, 2014
    flask通过特殊手段让一些全局变量来代理当前上下文的相关变量:
    http://flask.pocoo.org/docs/appcontext/
    http://werkzeug.pocoo.org/docs/local/

    原理细节你可以自己去探究,不过使用的时候你连教程都不相信,那也没办法了。。
    shinerene
        6
    shinerene  
    OP
       Jun 2, 2014
    @dagger 额 谢谢了 我还是相信教程的 只不过 我自己重新写了一个server-side的session 所以我不知道该如何使用它
    dagger
        7
    dagger  
       Jun 3, 2014
    用起来一样的,flask的模块化设计非常好,默认的session也只不过是SessionMixin、SessionInterface的一个实现罢了(SecureCookieSession、SecureCookieSessionInterface)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   978 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 19:52 · PVG 03:52 · LAX 12:52 · JFK 15:52
    ♥ Do have faith in what you're doing.